結果

問題 No.1245 ANDORゲーム(calc)
ユーザー poohbearpoohbear
提出日時 2020-10-03 14:28:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 264 ms / 2,000 ms
コード長 3,376 bytes
コンパイル時間 2,080 ms
コンパイル使用メモリ 202,012 KB
実行使用メモリ 4,408 KB
最終ジャッジ日時 2023-09-25 05:13:14
合計ジャッジ時間 8,596 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 7 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 6 ms
4,376 KB
testcase_10 AC 8 ms
4,380 KB
testcase_11 AC 263 ms
4,380 KB
testcase_12 AC 264 ms
4,376 KB
testcase_13 AC 261 ms
4,380 KB
testcase_14 AC 263 ms
4,376 KB
testcase_15 AC 261 ms
4,380 KB
testcase_16 AC 260 ms
4,376 KB
testcase_17 AC 239 ms
4,380 KB
testcase_18 AC 232 ms
4,376 KB
testcase_19 AC 223 ms
4,376 KB
testcase_20 AC 246 ms
4,384 KB
testcase_21 AC 243 ms
4,376 KB
testcase_22 AC 228 ms
4,376 KB
testcase_23 AC 257 ms
4,408 KB
testcase_24 AC 253 ms
4,380 KB
testcase_25 AC 175 ms
4,376 KB
testcase_26 AC 179 ms
4,380 KB
testcase_27 AC 186 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
//using namespace atcoder;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
typedef vector<vector<int> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;

#define debug(v) cout<<#v<<": ",prt(v);
template <typename A,typename B>
inline void prt(pair<A,B> p){cout<<"("<<p.first<<", "<<p.second<<")\n";}
template <typename A,typename B,typename C>
inline void prt(tuple<A,B,C> p){cout<<"("<<get<0>(p)<<", "<<get<1>(p)<<", "<<get<2>(p)<<")\n";}
inline void prt(bool p){if(p)cout<<"True"<<'\n';else cout<<"False"<<'\n';}
template <typename T> 
inline void prt(vector<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template<typename T> 
inline void prt(vector<vector<T> >& vv){ for(const auto& v : vv){ prt(v); } }
template <typename T> 
inline void prt(deque<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(unordered_map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename T> 
inline void prt(set<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}
template <typename T> 
inline void prt(multiset<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}
 



int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //input
    ll n,q;
    cin >> n >> q;
    vector<ll>a(n);
    rep(i,n)cin>>a[i];
    string s;
    cin >> s;
    //前計算
    //各bitに着目してn回の操作で何回変化するか
    //0-startの場合
    vector<ll>zero(62,0);
    
    rep(i,62){
        int now = 0;
        rep(j,n){
            if(now==0){
                if(s[j]=='1'&&((a[j]>>i)&1)){
                    now=1;
                    zero[i]++;
                }
            }
            else{
                if(s[j]=='0'&&(!((a[j]>>i)&1))){
                    now=0;
                    zero[i]++;
                }
                
            }
        }
    }

    //1-startの場合
    vector<ll>one(62,0);


    
    rep(i,62){
        int now = 1;
        rep(j,n){
            if(now==0){
                if(s[j]=='1'&&((a[j]>>i)&1)){
                    now=1;
                    one[i]++;
                }
            }
            else{
                if(s[j]=='0'&&(!((a[j]>>i)&1))){
                    now=0;
                    one[i]++;
                }
                
            }
        }
    }

    //query処理
    rep(i,q){
        ll t;
        cin >> t;
        ll ans = 0;
        ll two = 1;
        rep(j,62){
            if((t>>j)&1){
                ans += two*one[j];
            }
            else{
                ans += two*zero[j];
            }
            two*=2;
        }
        cout << ans << endl;
    }

    return 0;
}
0