結果

問題 No.1245 ANDORゲーム(calc)
ユーザー RubikunRubikun
提出日時 2020-10-02 22:26:55
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 1,654 bytes
コンパイル時間 1,521 ms
コンパイル使用メモリ 168,268 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-24 21:32:02
合計ジャッジ時間 5,223 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=100005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,Q;cin>>N>>Q;
    vector<ll> A(N),B(40),C(40);
    for(int i=0;i<N;i++) cin>>A[i];
    string S;cin>>S;
    
    for(int i=0;i<31;i++){
        int now0=0,now1=(1<<i);
        for(int j=0;j<si(S);j++){
            char c=S[j];
            int to0=now0,to1=now1;
            if(c=='0'){
                if(A[j]&(1<<i)){
                    to0&=(1<<i);
                    to1&=(1<<i);
                }else{
                    to0&=0;
                    to1&=0;
                }
            }else{
                if(A[j]&(1<<i)){
                    to0|=(1<<i);
                    to1|=(1<<i);
                }else{
                    to0|=0;
                    to1|=0;
                }
            }
            
            B[i]+=abs(now0-to0);
            C[i]+=abs(now1-to1);
            
            now0=to0;
            now1=to1;
        }
    }
    
    while(Q--){
        int x;cin>>x;
        ll ans=0;
        
        for(int i=0;i<31;i++){
            if(x&(1<<i)) ans+=C[i];
            else ans+=B[i];
        }
        
        cout<<ans<<"\n";
    }
}

0