結果

問題 No.1246 ANDORゲーム(max)
ユーザー eve__fuyuki
提出日時 2024-04-11 14:00:44
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 446 ms / 2,000 ms
コード長 710 bytes
コンパイル時間 2,336 ms
コンパイル使用メモリ 206,072 KB
最終ジャッジ日時 2025-02-20 23:53:09
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
void fast_io() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
}
int main() {
    fast_io();
    int n, t;
    cin >> n >> t;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    map<int, long long> dp;
    dp[t] = 0;
    for (int i = 0; i < n; i++) {
        map<int, long long> ndp;
        for (auto [k, v] : dp) {
            ndp[k | a[i]] = max(ndp[k | a[i]], v + abs(k - (k | a[i])));
            ndp[k & a[i]] = max(ndp[k & a[i]], v + abs(k - (k & a[i])));
        }
        swap(dp, ndp);
    }
    long long ans = 0;
    for (auto [k, v] : dp) {
        ans = max(ans, v);
    }
    cout << ans << endl;
}
0