結果

問題 No.1246 ANDORゲーム(max)
ユーザー 👑 tute7627tute7627
提出日時 2020-08-04 18:17:16
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 869 ms / 2,000 ms
コード長 1,254 bytes
コンパイル時間 3,047 ms
コンパイル使用メモリ 205,064 KB
最終ジャッジ日時 2025-01-12 14:21:08
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0