結果

問題 No.130 XOR Minimax
ユーザー renjyaku_intrenjyaku_int
提出日時 2020-09-18 17:38:42
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 158 ms / 5,000 ms
コード長 1,978 bytes
コンパイル時間 2,069 ms
コンパイル使用メモリ 204,092 KB
実行使用メモリ 54,820 KB
最終ジャッジ日時 2023-10-10 00:29:21
合計ジャッジ時間 4,938 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
6,540 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 67 ms
54,760 KB
testcase_05 AC 74 ms
54,820 KB
testcase_06 AC 64 ms
31,672 KB
testcase_07 AC 66 ms
30,800 KB
testcase_08 AC 158 ms
11,036 KB
testcase_09 AC 15 ms
7,508 KB
testcase_10 AC 22 ms
9,840 KB
testcase_11 AC 68 ms
27,132 KB
testcase_12 AC 8 ms
5,440 KB
testcase_13 AC 56 ms
21,996 KB
testcase_14 AC 148 ms
9,820 KB
testcase_15 AC 3 ms
4,348 KB
testcase_16 AC 106 ms
7,932 KB
testcase_17 AC 110 ms
7,968 KB
testcase_18 AC 121 ms
8,688 KB
testcase_19 AC 140 ms
9,632 KB
testcase_20 AC 72 ms
6,120 KB
testcase_21 AC 147 ms
9,828 KB
testcase_22 AC 35 ms
4,564 KB
testcase_23 AC 12 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//#include <tourist>
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> p;
const ll INF = 1e9 + 1;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//g++ yarudake.cpp -std=c++17 -I .
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll dfs(ll cur, vector<ll> a)
{
    ll res = 0;
    if (cur < 0)
        return 0;
    vector<ll> c, b;
    rep(i, a.size())
    {
        if ((a[i]) & (1<<cur))
            b.push_back(a[i]);
        else
            c.push_back(a[i]);
    }
    if (c.size() == 0 || b.size() == 0)
        return dfs(cur - 1, a);
    else
    {
        res += min(dfs(cur - 1, b), dfs(cur - 1, c));
        res += (1 << cur);
    }
    //cout<<res<<" "<<cur<<"\n";
    return res;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    cout << dfs(31, a) << "\n";
}
0