結果
| 問題 |
No.1245 ANDORゲーム(calc)
|
| コンテスト | |
| ユーザー |
Rubikun
|
| 提出日時 | 2020-10-02 22:26:55 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 84 ms / 2,000 ms |
| コード長 | 1,654 bytes |
| コンパイル時間 | 1,576 ms |
| コンパイル使用メモリ | 171,144 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-17 21:56:56 |
| 合計ジャッジ時間 | 5,050 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 |
ソースコード
#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";
}
}
Rubikun