結果
問題 | No.1246 ANDORゲーム(max) |
ユーザー |
|
提出日時 | 2020-10-17 22:13:50 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 431 ms / 2,000 ms |
コード長 | 1,278 bytes |
コンパイル時間 | 3,750 ms |
コンパイル使用メモリ | 204,044 KB |
最終ジャッジ日時 | 2025-01-15 11:24:00 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 31 |
ソースコード
#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;}