結果

問題 No.1245 ANDORゲーム(calc)
ユーザー milanis48663220milanis48663220
提出日時 2020-10-02 22:46:52
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 184 ms / 2,000 ms
コード長 1,337 bytes
コンパイル時間 1,845 ms
コンパイル使用メモリ 82,528 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-24 22:14:05
合計ジャッジ時間 6,243 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 5 ms
4,380 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 5 ms
4,380 KB
testcase_10 AC 6 ms
4,376 KB
testcase_11 AC 184 ms
4,376 KB
testcase_12 AC 183 ms
4,376 KB
testcase_13 AC 182 ms
4,376 KB
testcase_14 AC 181 ms
4,376 KB
testcase_15 AC 181 ms
4,380 KB
testcase_16 AC 177 ms
4,380 KB
testcase_17 AC 183 ms
4,376 KB
testcase_18 AC 181 ms
4,380 KB
testcase_19 AC 177 ms
4,380 KB
testcase_20 AC 181 ms
4,380 KB
testcase_21 AC 180 ms
4,376 KB
testcase_22 AC 181 ms
4,376 KB
testcase_23 AC 178 ms
4,376 KB
testcase_24 AC 178 ms
4,376 KB
testcase_25 AC 170 ms
4,380 KB
testcase_26 AC 171 ms
4,380 KB
testcase_27 AC 176 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int N, Q;
int A[100000];
ll ans[2][30];
string S;

void input(){
    cin >> N >> Q;
    for(int i = 0; i < N; i++) cin >> A[i];
    cin >> S;
}

void calc(){
    // 1
    int m = (1<<30)-1;
    for(int i = 0; i < N; i++){
        int n = m;
        if(S[i] == '0'){
            n &= A[i];
        }else{
            n |= A[i];
        }
        for(int j = 0; j < 30; j++){
            ans[1][j] += abs((n&(1<<j)) - (m&(1<<j)));           
        }
        m = n;
    }
    
    m = 0;
    for(int i = 0; i < N; i++){
        int n = m;
        if(S[i] == '0'){
            n &= A[i];
        }else{
            n |= A[i];
        }
        for(int j = 0; j < 30; j++){
            ans[0][j] += abs((n&(1<<j)) - (m&(1<<j)));           
        }
        m = n;
    }
}

void solve(){
    int t; cin >> t;
    ll ret = 0;
    
    for(int i = 0; i < 30; i++){
        if(t&(1<<i)){
            ret += ans[1][i];
        }else{
            ret += ans[0][i];
        }
    }
    cout << ret << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    input();
    calc();
    for(int i = 0; i < Q; i++) solve();
}
0