結果

問題 No.1245 ANDORゲーム(calc)
ユーザー 👑 tute7627tute7627
提出日時 2020-08-04 17:11:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 234 ms / 2,000 ms
コード長 1,499 bytes
コンパイル時間 2,273 ms
コンパイル使用メモリ 210,400 KB
実行使用メモリ 4,376 KB
最終ジャッジ日時 2023-10-13 08:57:42
合計ジャッジ時間 10,463 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,356 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,356 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 1 ms
4,356 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 5 ms
4,352 KB
testcase_08 AC 3 ms
4,352 KB
testcase_09 AC 5 ms
4,352 KB
testcase_10 AC 7 ms
4,348 KB
testcase_11 AC 211 ms
4,348 KB
testcase_12 AC 217 ms
4,356 KB
testcase_13 AC 221 ms
4,352 KB
testcase_14 AC 213 ms
4,348 KB
testcase_15 AC 215 ms
4,352 KB
testcase_16 AC 214 ms
4,352 KB
testcase_17 AC 227 ms
4,348 KB
testcase_18 AC 226 ms
4,348 KB
testcase_19 AC 234 ms
4,368 KB
testcase_20 AC 231 ms
4,352 KB
testcase_21 AC 222 ms
4,376 KB
testcase_22 AC 226 ms
4,352 KB
testcase_23 AC 208 ms
4,356 KB
testcase_24 AC 213 ms
4,352 KB
testcase_25 AC 179 ms
4,352 KB
testcase_26 AC 188 ms
4,348 KB
testcase_27 AC 208 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

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,q;cin>>n>>q;
  vector<int>a(n);
  rep(i,0,n)cin>>a[i];
  string s;cin>>s;
  auto f=[&](int x,int idx){
    pair<int,int> p;
    if(s[idx]=='0')p.first=x&a[idx];
    else p.first=x|a[idx];
    p.second=abs(p.first-x);
    return p;
  };
  ll res=0;
  vector<int>val(n+1);
  map<int,vector<int>>idx;
  int tmp=(1<<30)-1,change=(1<<30)-1;
  rep(i,0,n){
    auto p=f(val[i],i);
    val[i+1]=p.first;
    tmp=f(tmp,i).first;
    if(tmp^change^val[i+1]){
      ll k=tmp^change^val[i+1];
      rep(j,0,30){
        if(k&1<<j){
          idx[i].push_back(j);
          change^=1<<j;
        }
      }
    }
    else res+=p.second;
  }
  while(q--){
    int t;cin>>t;
    ll score=res;
    for(auto &v:idx){
      score+=f(t|val[v.first],v.first).second;
      for(auto z:v.second){
        t&=~(1<<z);
      }
    }
    cout<<score<<endl;
  }
  return 0;
}
0