結果
| 問題 |
No.1245 ANDORゲーム(calc)
|
| コンテスト | |
| ユーザー |
publfl
|
| 提出日時 | 2020-10-02 23:08:27 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 93 ms / 2,000 ms |
| コード長 | 803 bytes |
| コンパイル時間 | 225 ms |
| コンパイル使用メモリ | 32,768 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-17 23:21:40 |
| 合計ジャッジ時間 | 3,925 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 |
ソースコード
#include <stdio.h>
long long int score[100010][3];
int x[100010];
char y[100010];
int abs(int k)
{
return k>0?k:-k;
}
int main()
{
int a,b;
scanf("%d%d",&a,&b);
for(int i=1;i<=a;i++) scanf("%d",&x[i]);
scanf("%s",y+1);
for(int i=0;i<=30;i++)
{
int p,t;
t = 0, p = 0;
for(int j=1;j<=a;j++)
{
if(y[j]=='0') t = (t&x[j]);
else t = (t|x[j]);
score[i][0] += abs((t&(1<<i))-(p&(1<<i)));
p = t;
}
t = (1<<i), p = (1<<i);
for(int j=1;j<=a;j++)
{
if(y[j]=='0') t = (t&x[j]);
else t = (t|x[j]);
score[i][1] += abs((t&(1<<i))-(p&(1<<i)));
p = t;
}
}
for(int i=1;i<=b;i++)
{
int c;
scanf("%d",&c);
long long int ans = 0;
for(int j=0;j<=30;j++)
{
if((c&(1<<j))==0) ans += score[j][0];
else ans += score[j][1];
}
printf("%lld\n",ans);
}
}
publfl