結果
問題 |
No.1245 ANDORゲーム(calc)
|
ユーザー |
![]() |
提出日時 | 2020-10-02 22:01:23 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 122 ms / 2,000 ms |
コード長 | 1,360 bytes |
コンパイル時間 | 1,953 ms |
コンパイル使用メモリ | 194,128 KB |
最終ジャッジ日時 | 2025-01-15 00:18:31 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 |
ソースコード
#include<bits/stdc++.h> using namespace std; typedef long long ll; template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;} template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;} ll dx[4]={0,1,-1,0}; ll dy[4]={1,0,0,-1}; signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); ll n,q; cin>>n>>q; ll a[n]; for(int i=0;i<n;i++)cin>>a[i]; string s; cin>>s; ll t[44]={}; ll k[44]={}; for(ll i=0;i<44;i++){ ll now = (1LL<<i); for(int j=0;j<n;j++){ ll pre = now; if(s[j] == '0'){ now &= a[j]; } else{ now |= ((1LL << i) & a[j]); } t[i] += abs(pre - now); } } for(ll i=0;i<44;i++){ ll now = 0; for(int j=0;j<n;j++){ ll pre = now; if(s[j] == '0'){ now &= a[j]; } else{ now |= ((1LL << i) & a[j]); } k[i] += abs(pre - now); } } while(q--){ ll x; cin>>x; ll ans = 0; for(ll i=0;i<44;i++){ if(x & (1LL<<i))ans += t[i]; else ans += k[i]; } cout << ans << "\n"; } }