結果
問題 | No.1246 ANDORゲーム(max) |
ユーザー | 👑 tute7627 |
提出日時 | 2020-08-04 18:17:16 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 721 ms / 2,000 ms |
コード長 | 1,254 bytes |
コンパイル時間 | 2,120 ms |
コンパイル使用メモリ | 212,304 KB |
実行使用メモリ | 201,916 KB |
最終ジャッジ日時 | 2023-10-12 21:28:41 |
合計ジャッジ時間 | 12,430 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,352 KB |
testcase_01 | AC | 2 ms
4,352 KB |
testcase_02 | AC | 1 ms
4,352 KB |
testcase_03 | AC | 1 ms
4,352 KB |
testcase_04 | AC | 1 ms
4,352 KB |
testcase_05 | AC | 1 ms
4,352 KB |
testcase_06 | AC | 2 ms
4,348 KB |
testcase_07 | AC | 2 ms
4,348 KB |
testcase_08 | AC | 2 ms
4,352 KB |
testcase_09 | AC | 2 ms
4,348 KB |
testcase_10 | AC | 1 ms
4,352 KB |
testcase_11 | AC | 17 ms
7,452 KB |
testcase_12 | AC | 4 ms
4,352 KB |
testcase_13 | AC | 7 ms
4,708 KB |
testcase_14 | AC | 25 ms
9,868 KB |
testcase_15 | AC | 25 ms
9,732 KB |
testcase_16 | AC | 709 ms
199,888 KB |
testcase_17 | AC | 712 ms
201,372 KB |
testcase_18 | AC | 712 ms
201,776 KB |
testcase_19 | AC | 710 ms
201,132 KB |
testcase_20 | AC | 712 ms
201,732 KB |
testcase_21 | AC | 713 ms
201,916 KB |
testcase_22 | AC | 721 ms
201,724 KB |
testcase_23 | AC | 54 ms
14,256 KB |
testcase_24 | AC | 557 ms
200,940 KB |
testcase_25 | AC | 550 ms
200,672 KB |
testcase_26 | AC | 547 ms
200,656 KB |
testcase_27 | AC | 54 ms
20,672 KB |
testcase_28 | AC | 547 ms
194,376 KB |
testcase_29 | AC | 548 ms
195,136 KB |
testcase_30 | AC | 544 ms
193,624 KB |
testcase_31 | AC | 69 ms
33,120 KB |
testcase_32 | AC | 69 ms
33,024 KB |
testcase_33 | AC | 68 ms
33,032 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; #define ALL(a) (a).begin(),(a).end() #define ALLR(a) (a).rbegin(),(a).rend() #define rep(i,n,m) for(int i = (n); i < (int)(m); i++) #define rrep(i,n,m) for(int i = (m) - 1; i >= (int)(n); i--) using ll = long long; using ld = long double; const ll MOD1 = 1e9+7; const ll MOD9 = 998244353; const int INF = (int)1e9+1; template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}else return false;} template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}else return false;} template<typename T> vector<ll>dx={1,0,-1,0,1,1,-1,-1}; vector<ll>dy={0,1,0,-1,1,-1,1,-1}; int main(){ int n,t; cin>>n>>t; vector<int>a(n); rep(i,0,n)cin>>a[i]; vector<map<int,ll>>dp(n+1); dp[0][t]=0; rep(i,0,n){ auto ope=[&](pair<int,ll>pre,int cmd){ pair<int,ll>nxt=pre; if(cmd==0)nxt.first&=a[i]; else nxt.first|=a[i]; nxt.second+=abs(nxt.first-pre.first); return nxt; }; for(auto p:dp[i]){ rep(j,0,2){ auto nxt=ope(p,j); if(dp[i+1].count(nxt.first))chmax(dp[i+1][nxt.first],nxt.second); else dp[i+1][nxt.first]=nxt.second; } } } ll ret=0; for(auto p:dp[n])chmax(ret,p.second); cout<<ret<<endl; return 0; }