結果
| 問題 |
No.2040 010-1 Deletion
|
| コンテスト | |
| ユーザー |
publfl2
|
| 提出日時 | 2022-08-12 23:16:50 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 190 ms / 3,000 ms |
| コード長 | 1,190 bytes |
| コンパイル時間 | 212 ms |
| コンパイル使用メモリ | 32,896 KB |
| 実行使用メモリ | 144,512 KB |
| 最終ジャッジ日時 | 2024-11-09 00:49:17 |
| 合計ジャッジ時間 | 6,874 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 33 |
コンパイルメッセージ
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;
| ^~~
ソースコード
#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);
}
publfl2