結果

問題 No.130 XOR Minimax
ユーザー PachicobuePachicobue
提出日時 2017-07-28 02:33:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,371 bytes
コンパイル時間 1,840 ms
コンパイル使用メモリ 178,844 KB
実行使用メモリ 21,056 KB
最終ジャッジ日時 2024-04-18 09:15:13
合計ジャッジ時間 14,520 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define show(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz:" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = 1e9 + 7;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;

int main()
{
    ll N;
    cin >> N;
    vector<ll> a(N);
    ll max_digits = 0;
    for (ll i = 0; i < N; i++) {
        cin >> a[i];
        max_digits = max(max_digits, (ll)log2(a[i] - 1) + 1);
    }
    max_digits++;
    sort(a.begin(), a.end());
    a.erase(unique(a.begin(), a.end()), a.end());
    N = a.size();
    vector<pair<ll, int>> b(N);
    for (ll i = 0; i < N; i++) {
        b[i].first = a[i];
        b[i].second = i;
    }

    vector<vector<bool>> digit(N, vector<bool>(max_digits, false));
    for (ll i = 0; i < N; i++) {
        ll num = a[i];
        for (ll j = 0; j < max_digits; j++) {
            digit[i][j] = (bool)(num % 2);
            num /= 2;
        }
    }
    ll mini = INF<ll>;
    for (ll i = 0; i < N; i++) {
        ll suff = 0;
        ll maximum = 0;
        auto lower = b.begin();
        auto upper = b.end();
        for (ll d = max_digits - 1; d >= 0; d--) {
            const ll inf = suff;
            const ll sup = suff + (1LL << (d + 1)) - 1;
            upper = upper_bound(lower, upper, make_pair(sup, INF<int>));
            lower = lower_bound(lower, upper, make_pair(inf, 0));
            if (upper - lower == 1) {
                break;
            }
            const bool first = digit[lower->second][d];
            bool same = true;
            for (auto it = lower + 1; it != upper; it++) {
                if (first != digit[it->second][d]) {
                    same = false;
                    break;
                }
            }
            if (not same) {
                maximum += 1LL << d;
            }
            suff += (ll)(digit[i][d]) << d;
        }
        mini = min(mini, maximum);
    }
    cout << mini << endl;

    return 0;
}
0