結果

問題 No.2040 010-1 Deletion
ユーザー publfl2publfl2
提出日時 2022-08-12 23:16:50
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 138 ms / 3,000 ms
コード長 1,190 bytes
コンパイル時間 178 ms
コンパイル使用メモリ 33,792 KB
実行使用メモリ 145,152 KB
最終ジャッジ日時 2024-04-26 10:17:33
合計ジャッジ時間 4,863 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
144,896 KB
testcase_01 AC 47 ms
144,956 KB
testcase_02 AC 47 ms
144,804 KB
testcase_03 AC 46 ms
145,100 KB
testcase_04 AC 46 ms
145,024 KB
testcase_05 AC 48 ms
144,996 KB
testcase_06 AC 47 ms
144,896 KB
testcase_07 AC 47 ms
144,896 KB
testcase_08 AC 49 ms
145,024 KB
testcase_09 AC 47 ms
144,832 KB
testcase_10 AC 46 ms
145,024 KB
testcase_11 AC 133 ms
145,024 KB
testcase_12 AC 132 ms
145,024 KB
testcase_13 AC 132 ms
145,024 KB
testcase_14 AC 129 ms
145,008 KB
testcase_15 AC 138 ms
145,048 KB
testcase_16 AC 130 ms
144,976 KB
testcase_17 AC 48 ms
144,856 KB
testcase_18 AC 132 ms
145,012 KB
testcase_19 AC 57 ms
144,816 KB
testcase_20 AC 52 ms
144,896 KB
testcase_21 AC 80 ms
145,004 KB
testcase_22 AC 87 ms
145,024 KB
testcase_23 AC 119 ms
145,100 KB
testcase_24 AC 130 ms
145,152 KB
testcase_25 AC 107 ms
145,040 KB
testcase_26 AC 99 ms
145,024 KB
testcase_27 AC 111 ms
145,024 KB
testcase_28 AC 99 ms
145,144 KB
testcase_29 AC 116 ms
145,152 KB
testcase_30 AC 86 ms
145,056 KB
testcase_31 AC 126 ms
145,096 KB
testcase_32 AC 130 ms
145,068 KB
testcase_33 AC 126 ms
145,108 KB
testcase_34 AC 126 ms
144,964 KB
testcase_35 AC 127 ms
145,020 KB
testcase_36 AC 122 ms
145,084 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'long long int func(int, int, int)':
main.cpp:41:39: warning: 'ans' may be used uninitialized [-Wmaybe-uninitialized]
   41 |         return check[s][t+1500][type] = ans;
      |                ~~~~~~~~~~~~~~~~~~~~~~~^~~~~
main.cpp:16:23: note: 'ans' was declared here
   16 |         long long int ans;
      |                       ^~~

ソースコード

diff #

#include <stdio.h>
#define MOD 998244353

int a;
long long int check[1510][3010][4];
char x[1510];
long long int func(int s, int t, int type)
{
	if(s>a)
	{
		if(t<=0&& (-t)%2==0) return 1;
		else return 0;
	}
	if(check[s][t+1500][type]!=-1) return check[s][t+1500][type];
	
	long long int ans;
	if(type==0) // last = 0
	{
		long long int s1 = func(s+1,t+1,0);
		long long int s2 = func(s+1,t,1);
		if(x[s]=='0') s2 = 0;
		if(x[s]=='1') s1 = 0;
		ans = (s1+s2)%MOD;
	}
	if(type==1) // last = 01
	{
		long long int s1 = func(s+1,t-1,2);
		long long int s2 = func(s+1,t,1);
		if(x[s]=='0') s2 = 0;
		if(x[s]=='1') s1 = 0;
		ans = (s1+s2)%MOD;
	}
	if(type==2) // last = 010
	{
		long long int s1 = func(s+1,t+1,0);
		long long int s2 = func(s+1,t,1);
		if(x[s]=='0') s2 = 0;
		if(x[s]=='1') s1 = 0;
		ans = (s1+s2)%MOD;
	}
	return check[s][t+1500][type] = ans;
}

int main()
{
	scanf("%d",&a);
	for(int i=0;i<=1500;i++) for(int j=0;j<=3000;j++) for(int k=0;k<=2;k++) check[i][j][k] = -1;
	scanf("%s",x+1);
	
	long long int ans = 0;
	for(int i=1;i<=a;i++)
	{
		if(x[i]=='1') continue;
		ans += func(i+1,1,0), ans %= MOD;
		if(x[i]=='0') goto u;
	}
	ans++, ans %= MOD;
	u:;
	printf("%lld",ans);
}
0