結果

問題 No.1246 ANDORゲーム(max)
ユーザー publflpublfl
提出日時 2020-10-02 23:19:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 817 bytes
コンパイル時間 171 ms
コンパイル使用メモリ 32,292 KB
実行使用メモリ 8,564 KB
最終ジャッジ日時 2023-09-24 23:28:06
合計ジャッジ時間 4,355 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 WA -
testcase_03 AC 2 ms
4,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

int x[100010];
long long int check[3][40][100010];
int a;
int abs(int k)
{
	return k>0?k:-k;
}
long long int func(int k, int s, int t)
{
	if(t>a) return 0;
	if(check[k][s][t]>0) return check[k][s][t];
	
	int s1 = ((k<<s)&x[t]);
	int s2 = ((k<<s)|x[t]);
	long long int t1,t2;
	if((s1&(1<<s))==0) t1 = func(0,s,t+1) + abs(((s1&(1<<s))) - (k<<s));
	else t1 = func(1,s,t+1) + abs(((s1&(1<<s))) - (k<<s));
	if((s2&(1<<s))==0) t2 = func(0,s,t+1) + abs(((s2&(1<<s))) - (k<<s));
	else t2 = func(1,s,t+1) + abs(((s2&(1<<s))) - (k<<s));
	return check[k][s][t] = t1>t2?t1:t2;
}
int main()
{
	int b;
	scanf("%d%d",&a,&b);
	for(int i=1;i<=a;i++) scanf("%d",&x[i]);
	
	long long int ans = 0;
	for(int i=0;i<=30;i++)
	{
		if((b&(1<<i))==0) ans += func(0,i,1);
		else ans += func(1,i,1);
	}
	printf("%lld",ans);
}
0