結果
| 問題 | 
                            No.1245 ANDORゲーム(calc)
                             | 
                    
| コンテスト | |
| ユーザー | 
                             IKyopro
                         | 
                    
| 提出日時 | 2020-10-02 23:46:25 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 86 ms / 2,000 ms | 
| コード長 | 1,276 bytes | 
| コンパイル時間 | 1,920 ms | 
| コンパイル使用メモリ | 199,504 KB | 
| 最終ジャッジ日時 | 2025-01-15 01:27:28 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 25 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template<class T> bool chmin(T& a,T b){if(a>b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b){if(a<b) {a = b; return true;} return false;}
#define all(x) (x).begin(),(x).end()
#define debug(x)  cerr << #x << " = " << (x) << endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,Q;
    cin >> N >> Q;
    vec<ll> A(N);
    for(auto& x:A) cin >> x;
    string S;
    cin >> S;
    int K = 30;
    vvec<ll> sum(K,vec<ll>(2));
    for(int k=0;k<30;k++){
        for(int j=0;j<2;j++){
            int now = j;
            for(int i=0;i<N;i++){
                if(S[i]=='0'){
                    int ne = now && (A[i]>>k&1);
                    sum[k][j] += abs(now-ne)*(1<<k);
                    now = ne;
                }else{
                    int ne = now || (A[i]>>k&1);
                    sum[k][j] += abs(now-ne)*(1<<k);
                    now = ne;   
                }
            }
        }
    }
    while(Q--){
        int t;
        cin >> t;
        ll ans = 0;
        for(int k=0;k<K;k++) ans += sum[k][t>>k&1];
        cout << ans << "\n";
    }
}
            
            
            
        
            
IKyopro