結果

問題 No.1245 ANDORゲーム(calc)
ユーザー むかでむかで
提出日時 2020-10-02 22:50:52
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 2,179 bytes
コンパイル時間 1,989 ms
コンパイル使用メモリ 200,752 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-24 22:22:20
合計ジャッジ時間 6,176 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 82 ms
4,376 KB
testcase_12 AC 82 ms
4,380 KB
testcase_13 AC 82 ms
4,376 KB
testcase_14 AC 82 ms
4,376 KB
testcase_15 AC 81 ms
4,380 KB
testcase_16 AC 82 ms
4,376 KB
testcase_17 AC 69 ms
4,376 KB
testcase_18 AC 64 ms
4,376 KB
testcase_19 AC 60 ms
4,380 KB
testcase_20 AC 70 ms
4,380 KB
testcase_21 AC 67 ms
4,380 KB
testcase_22 AC 62 ms
4,376 KB
testcase_23 AC 76 ms
4,376 KB
testcase_24 AC 75 ms
4,376 KB
testcase_25 AC 34 ms
4,380 KB
testcase_26 AC 36 ms
4,380 KB
testcase_27 AC 40 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define ins insert

#define debug(a) cerr<<(a)<<endl
#define dbrep(a,n) rep(_i,n) cerr<<(a[_i])<<" "; cerr<<endl
#define dbrep2(a,n,m) rep(_i,n){rep(_j,m) cerr<<(a[_i][_j])<<" "; cerr<<endl;}

using namespace std;

template<class A, class B>
ostream &operator<<(ostream &os, const pair<A,B> &p){return os<<"("<<p.fi<<","<<p.se<<")";}
template<class A, class B>
istream &operator>>(istream &is, pair<A,B> &p){return is>>p.fi>>p.se;}

/* Some Libraries */

//-------------------------------------------------

ll calc[30][2];

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,Q; cin>>N>>Q;
    vi a(N);
    rep(i,N) cin>>a[i];
    string S; cin>>S;
    rep(i,30){
        ll m=1<<i;
        rep(j,2){
            ll sum=0;
            int cur = j;
            rep(k,N){
                int b = a[k]>>i&1;
                if (S[k]=='0'){
                    if (cur==1 && b==0){
                        cur=0;
                        sum+=m;
                    }
                }else{
                    if (cur==0 && b==1){
                        cur=1;
                        sum+=m;
                    }
                }
            }
            calc[i][j]=sum;
        }
    }
    while(Q--){
        int t; cin>>t;
        ll ans=0;
        rep(i,30){
            ans+=calc[i][t>>i&1];
        }
        cout<<ans<<"\n";
    }
    return 0;
}
0