結果
問題 | No.1246 ANDORゲーム(max) |
ユーザー | yukudo |
提出日時 | 2020-10-07 11:00:58 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 452 ms / 2,000 ms |
コード長 | 1,249 bytes |
コンパイル時間 | 1,560 ms |
コンパイル使用メモリ | 174,636 KB |
実行使用メモリ | 4,504 KB |
最終ジャッジ日時 | 2023-09-27 09:11:00 |
合計ジャッジ時間 | 9,552 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,376 KB |
testcase_01 | AC | 1 ms
4,380 KB |
testcase_02 | AC | 1 ms
4,384 KB |
testcase_03 | AC | 1 ms
4,376 KB |
testcase_04 | AC | 1 ms
4,376 KB |
testcase_05 | AC | 1 ms
4,380 KB |
testcase_06 | AC | 1 ms
4,376 KB |
testcase_07 | AC | 1 ms
4,380 KB |
testcase_08 | AC | 1 ms
4,380 KB |
testcase_09 | AC | 1 ms
4,380 KB |
testcase_10 | AC | 1 ms
4,376 KB |
testcase_11 | AC | 10 ms
4,376 KB |
testcase_12 | AC | 3 ms
4,376 KB |
testcase_13 | AC | 4 ms
4,376 KB |
testcase_14 | AC | 16 ms
4,376 KB |
testcase_15 | AC | 16 ms
4,380 KB |
testcase_16 | AC | 439 ms
4,376 KB |
testcase_17 | AC | 433 ms
4,504 KB |
testcase_18 | AC | 448 ms
4,376 KB |
testcase_19 | AC | 437 ms
4,380 KB |
testcase_20 | AC | 452 ms
4,380 KB |
testcase_21 | AC | 439 ms
4,380 KB |
testcase_22 | AC | 445 ms
4,380 KB |
testcase_23 | AC | 17 ms
4,376 KB |
testcase_24 | AC | 272 ms
4,376 KB |
testcase_25 | AC | 278 ms
4,376 KB |
testcase_26 | AC | 293 ms
4,380 KB |
testcase_27 | AC | 21 ms
4,376 KB |
testcase_28 | AC | 283 ms
4,380 KB |
testcase_29 | AC | 311 ms
4,380 KB |
testcase_30 | AC | 292 ms
4,376 KB |
testcase_31 | AC | 33 ms
4,376 KB |
testcase_32 | AC | 33 ms
4,376 KB |
testcase_33 | AC | 32 ms
4,376 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i) #define ALL(v) (v).begin(),(v).end() #define CLR(t,v) memset(t,(v),sizeof(t)) template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";} template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;} template<class T>void chmin(T&a,const T&b){if(a>b)a=b;} template<class T>void chmax(T&a,const T&b){if(a<b)a=b;} ll nextLong() { ll x; scanf("%lld", &x); return x;} int main2() { int N = nextLong(); int T = nextLong(); vector<int> A(N); REP(i, N) A[i] = nextLong(); map<int, ll> dp; dp[T] = 0; REP(i, N) { map<int, ll> ndp; for (auto p : dp) { int t = p.first; ll score = p.second; REP(k, 2) { int nt = (k == 0) ? (t & A[i]) : (t | A[i]); ll nscore = score + abs(t - nt); if (ndp.count(nt) == 0 || ndp[nt] < nscore) { ndp[nt] = nscore; } } } swap(dp, ndp); } ll ans = 0; for (auto p : dp) chmax(ans, p.second); cout << ans << endl; return 0; } int main() { #ifdef LOCAL for (;!cin.eof();cin>>ws) #endif main2(); return 0; }