結果

問題 No.130 XOR Minimax
ユーザー PachicobuePachicobue
提出日時 2017-07-28 01:20:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,157 bytes
コンパイル時間 1,988 ms
コンパイル使用メモリ 174,568 KB
実行使用メモリ 11,392 KB
最終ジャッジ日時 2024-04-18 09:12:43
合計ジャッジ時間 5,031 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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());
    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;
        }
    }
    vector<bool> same(max_digits, true);
    for (ll d = 0; d < max_digits; d++) {
        const bool first = digit[0][d];
        for (ll i = 1; i < N; i++) {
            if (first != digit[i][d]) {
                same[d] = false;
                break;
            }
        }
    }

    ll mini = INF<ll>;
    for (ll i = 0; i < N; i++) {
        ll x = 0;
        ll maximum = 0;
        for (ll d = max_digits - 1; d >= 0; d--) {
            if (same[d]) {
                x += ((ll)digit[i][d] << d);
            } else {
                const ll inf = x;
                const ll sup = x + (1LL << (d + 1)) - 1;
                const ll cand = upper_bound(a.begin(), a.end(), sup) - lower_bound(a.begin(), a.end(), inf);
                if (cand == 0) {
                    break;
                }
                x += ((ll)(not digit[i][d]) << d);
                maximum += 1LL << d;
            }
        }
        mini = min(mini, maximum);
    }
    cout << mini << endl;

    return 0;
}
0