結果

問題 No.1246 ANDORゲーム(max)
ユーザー kimiyukikimiyuki
提出日時 2020-10-17 22:13:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 391 ms / 2,000 ms
コード長 1,278 bytes
コンパイル時間 1,890 ms
コンパイル使用メモリ 210,160 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-28 08:42:29
合計ジャッジ時間 9,297 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 10 ms
4,380 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 4 ms
4,380 KB
testcase_14 AC 15 ms
4,380 KB
testcase_15 AC 14 ms
4,376 KB
testcase_16 AC 387 ms
4,376 KB
testcase_17 AC 388 ms
4,380 KB
testcase_18 AC 391 ms
4,380 KB
testcase_19 AC 388 ms
4,376 KB
testcase_20 AC 391 ms
4,380 KB
testcase_21 AC 391 ms
4,380 KB
testcase_22 AC 384 ms
4,380 KB
testcase_23 AC 17 ms
4,376 KB
testcase_24 AC 254 ms
4,376 KB
testcase_25 AC 253 ms
4,376 KB
testcase_26 AC 264 ms
4,376 KB
testcase_27 AC 19 ms
4,376 KB
testcase_28 AC 234 ms
4,380 KB
testcase_29 AC 230 ms
4,380 KB
testcase_30 AC 235 ms
4,376 KB
testcase_31 AC 27 ms
4,376 KB
testcase_32 AC 26 ms
4,376 KB
testcase_33 AC 28 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++(i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++(i))
#define REP_R(i, n) for (int i = (int)(n)-1; (i) >= 0; --(i))
#define REP3R(i, m, n) for (int i = (int)(n)-1; (i) >= (int)(m); --(i))
#define ALL(x) ::std::begin(x), ::std::end(x)
using namespace std;

int64_t solve(int n, int64_t t, const vector<int64_t>& a) {
    map<int64_t, int64_t> cur;
    cur[t] = 0;
    REP (i, n) {
        map<int64_t, int64_t> prv;
        cur.swap(prv);
        for (auto [x, prv_x] : prv) {
            cur[x & a[i]] = max(cur[x & a[i]], prv_x + abs<int64_t>((x & a[i]) - x));
            cur[x | a[i]] = max(cur[x | a[i]], prv_x + abs<int64_t>((x | a[i]) - x));
        }
    }
    int64_t ans = 0;
    for (auto [x, cur_x] : cur) {
        ans = max(ans, cur_x);
    }
    return ans;
}

// generated by online-judge-template-generator v4.7.1 (https://github.com/online-judge-tools/template-generator)
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    constexpr char endl = '\n';
    int64_t N;
    int64_t T;
    cin >> N;
    vector<int64_t> A(N);
    cin >> T;
    REP (i, N) { cin >> A[i]; }
    auto ans = solve(N, T, A);
    cout << ans << endl;
    return 0;
}
0