結果

問題 No.1245 ANDORゲーム(calc)
ユーザー publflpublfl
提出日時 2020-10-02 23:08:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 91 ms / 2,000 ms
コード長 803 bytes
コンパイル時間 228 ms
コンパイル使用メモリ 32,296 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-24 23:00:12
合計ジャッジ時間 4,188 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 90 ms
4,376 KB
testcase_12 AC 91 ms
4,380 KB
testcase_13 AC 90 ms
4,376 KB
testcase_14 AC 90 ms
4,376 KB
testcase_15 AC 90 ms
4,376 KB
testcase_16 AC 90 ms
4,376 KB
testcase_17 AC 84 ms
4,380 KB
testcase_18 AC 79 ms
4,376 KB
testcase_19 AC 77 ms
4,380 KB
testcase_20 AC 85 ms
4,380 KB
testcase_21 AC 82 ms
4,376 KB
testcase_22 AC 77 ms
4,376 KB
testcase_23 AC 90 ms
4,376 KB
testcase_24 AC 90 ms
4,380 KB
testcase_25 AC 56 ms
4,380 KB
testcase_26 AC 58 ms
4,380 KB
testcase_27 AC 62 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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);
	}
}
0