QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#751521#9489. 0100 InsertionAcoippAC ✓286ms19476kbC++141.1kb2024-11-15 19:15:112024-11-15 19:15:11

Judging History

你现在查看的是最新测评结果

  • [2024-11-15 19:15:11]
  • 评测
  • 测评结果:AC
  • 用时:286ms
  • 内存:19476kb
  • [2024-11-15 19:15:11]
  • 提交

answer

#include<bits/stdc++.h>
#define ll int
#define N 1005
#define mod 998244353
using namespace std;
ll n,i,f[N][N][2],g[N][N][2],h[N][N],j,k,ans,dw,up;
char s[N];
inline void add(ll &x,ll y){(x+=y)>=mod&&(x-=mod);}
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>(s+1);
	reverse(s+1,s+n+1);
	f[0+n][0+n][0] = 1;
	for(i=1;i<=n;i++){
		if(s[i]!='1'){
			for(j=dw;j<=up;j++){
				for(k=dw;k<=0;k++){
					if(!f[j+n][k+n][0]&&!f[j+n][k+n][1]) continue;
					add(g[j+1+n][k+n][0],f[j+n][k+n][0]);
					add(g[j+1+n][k+n][0],f[j+n][k+n][1]);
				}
			}
		}
		if(s[i]!='0'&&i!=n&&i!=1&&i!=2){
			for(j=dw;j<=up;j++){
				for(k=dw;k<=0;k++){
					if(!f[j+n][k+n][0]) continue;
					if(k-j+3>=2) continue;
					add(g[j-3+n][min(k,j-3)+n][1],f[j+n][k+n][0]);
				}
			}
		}
		if(s[i]=='?'||s[i]=='1') dw=max(-n,max(dw-3,(i+1)/2*(-3)));
		if(s[i]=='?'||s[i]=='0') up=min(n,up+1);
		for(j=dw;j<=up;j++) for(k=dw;k<=0;k++) f[j+n][k+n][0]=g[j+n][k+n][0],f[j+n][k+n][1]=g[j+n][k+n][1],g[j+n][k+n][0]=g[j+n][k+n][1]=0;
	}
	for(i=-n;i<=0;i++) add(ans,f[0+n][i+n][0]);
	cout<<ans<<endl;
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5764kb

input:

8
0??0?100

output:

2

result:

ok "2"

Test #2:

score: 0
Accepted
time: 1ms
memory: 5736kb

input:

4
?10?

output:

1

result:

ok "1"

Test #3:

score: 0
Accepted
time: 1ms
memory: 5956kb

input:

28
???????????0???0??????1???0?

output:

2023

result:

ok "2023"

Test #4:

score: 0
Accepted
time: 1ms
memory: 5752kb

input:

4
????

output:

1

result:

ok "1"

Test #5:

score: 0
Accepted
time: 1ms
memory: 5796kb

input:

8
11111111

output:

0

result:

ok "0"

Test #6:

score: 0
Accepted
time: 283ms
memory: 19388kb

input:

500
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...

output:

870731023

result:

ok "870731023"

Test #7:

score: 0
Accepted
time: 286ms
memory: 19364kb

input:

500
???????????????????0???????????????????????????????????????0??????????????????????1???????????????????????????????????????00????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????1???????????????????????????????????...

output:

763641704

result:

ok "763641704"

Test #8:

score: 0
Accepted
time: 89ms
memory: 14188kb

input:

344
?0???????????1???????0?0?????0?????????????0?0????0?0??1??0?????0??0???1?????0????00?????1?????1????????1?????10????0??????????1????0???1????????0???10?????1?0?0???1??????????0??0???1?0??00??0???????001????????1????1??????1?0????1??????????????????1????1????????????0???????????01?1??????0?0?????...

output:

273835616

result:

ok "273835616"

Test #9:

score: 0
Accepted
time: 9ms
memory: 9276kb

input:

152
?1???1??????????????????00??????????0?????0????????0??1?????0????0????????0????010???????????????1??1??????0?10??1????0???????????????1?????0???1???????

output:

539361138

result:

ok "539361138"

Test #10:

score: 0
Accepted
time: 26ms
memory: 12116kb

input:

216
???????1?????1??1????1???1?????????????0?1???????????????????????????????????????????????1?????????????????10???0???1???????????????????????1????????????0???????0??????0?????????1???????????????????????1?????????0???

output:

336079328

result:

ok "336079328"

Test #11:

score: 0
Accepted
time: 68ms
memory: 15884kb

input:

316
??????00?????????????????????1??????????????????0?????????????????0??0??????0???1??1?????????0??????????????????????0?????????0?0?1??0?????1?1??????1?1?????????????????????????????????0??????????????????????10???????1???????????1?????????????1????1????????????0????????????????1????1???0??0??1???...

output:

919261244

result:

ok "919261244"

Test #12:

score: 0
Accepted
time: 80ms
memory: 14120kb

input:

340
?0?001??1?0????1?????1???01?????????1??01??0???1???1?????????????0?1??????1??1?10??0????????10?????1????1?010???1?????????????1???????1????01???????1???????00???1?0?00??0????????00???0??????1??1?1?????10??1????0??1????1????0????????0????0??????00?0??00???1??001????????0?1?????????????????0???1??...

output:

743485908

result:

ok "743485908"

Test #13:

score: 0
Accepted
time: 135ms
memory: 17384kb

input:

392
??????0??????????10???????????????????????1????????1???????0???????????0??????????????101???????????????????????0??????????0??0??????????1?????1???????????????????1?0?????????????1???????????????????????1????????0???0?????1????????????????0??????1?????????????0????????????????0?????????????????1...

output:

213859453

result:

ok "213859453"

Test #14:

score: 0
Accepted
time: 3ms
memory: 6516kb

input:

96
????????0??1??1??????????????????????????1?0?????0??????1?????????1?0?????00??????????1???1?????

output:

860127276

result:

ok "860127276"

Test #15:

score: 0
Accepted
time: 5ms
memory: 8876kb

input:

116
???????????????????????????????01?1???????????????0?00????0?????????????????1?0?????????????????1???????????????00??

output:

717954632

result:

ok "717954632"

Test #16:

score: 0
Accepted
time: 49ms
memory: 13128kb

input:

280
?????1????0??0??????1????????0????0?1?0????????00???0???????0????0???????????1?0?1???????????1?????10????1??????100??????????1?1?????01?1??????0????01??1???1?????0????????0?1?0???????????01??00??????1?????????????????1?1?????????1????????????????0????????????????????????0????????

output:

553679844

result:

ok "553679844"

Test #17:

score: 0
Accepted
time: 31ms
memory: 12796kb

input:

260
????????0????0???????????????1???????0?00??0???????????????0??????0?????1?????????????????????????????????????0???????1????????0??????????????????????1???????????????????1?0????1???????00?0????10???????????0?1?10??????????????????0??0???????1???????1??1???????

output:

121486637

result:

ok "121486637"

Test #18:

score: 0
Accepted
time: 276ms
memory: 19476kb

input:

500
??0????1???1??????1?1??????????????????????????????????0??0??????????????????????1???????01????????0???0???????????????????????1????????1??????????????1????????0?1???0?????0???????????????????0??????????????1????????0???????0?0??????????????0???????1???????1??????????????????????????0????0??????...

output:

397451125

result:

ok "397451125"

Test #19:

score: 0
Accepted
time: 273ms
memory: 19188kb

input:

500
??????1???????????????????0????????????????????????0??????0???????????1??????????10???0???0?????????????1??1????????0??????1???????????00????????????0???????????????????1??0???0????0?????????????0?????????????????????????????????????0????0??????????1??????????????????????????????????????????????...

output:

248838567

result:

ok "248838567"

Test #20:

score: 0
Accepted
time: 271ms
memory: 19148kb

input:

500
?0??0????1???????????????????????????1????????????????????0????????1????????????????1????0?????????????1???????????1?0????????????????????0?????????????0????0????????????1????????1????????????????0???0?1???1???1???????????1?????1???0??????????1????????1?????1???0?1???????????1???????????????????...

output:

53824210

result:

ok "53824210"

Test #21:

score: 0
Accepted
time: 2ms
memory: 6384kb

input:

76
????0????????0??0???1??0??????00?0????0???1??????1?0????0?1?????????????1???

output:

205686585

result:

ok "205686585"

Test #22:

score: 0
Accepted
time: 1ms
memory: 7980kb

input:

24
?0?0?????0??????????????

output:

587

result:

ok "587"

Test #23:

score: 0
Accepted
time: 2ms
memory: 8364kb

input:

76
?????0?????????????????0????????????????????????????1???0???????????????????

output:

83575746

result:

ok "83575746"

Test #24:

score: 0
Accepted
time: 1ms
memory: 5956kb

input:

28
00???0???0?0??0???0???0?????

output:

859

result:

ok "859"

Test #25:

score: 0
Accepted
time: 1ms
memory: 8100kb

input:

44
?00??1???00??1???0??1?100??1?0???0??1???0???

output:

63

result:

ok "63"

Test #26:

score: 0
Accepted
time: 195ms
memory: 18020kb

input:

444
???0???0???????????????1?????1??????0?????1??????1??????????10?1???????????????????????????????1?1??00?0??0????0??????????1???????101?0????10??????????????0?0???????1???????????????1????????0?????????1????????????1???0??????????????????????????0??????1??????????0???10??1???????????01????????????...

output:

847293915

result:

ok "847293915"

Test #27:

score: 0
Accepted
time: 241ms
memory: 18660kb

input:

484
?????1?1???????????1?????1??????????0?1???????????1?????0?1???0000?1?1?0?00????1????0?0?00?????????????????????1????????1?01??????01??1?????0??????0???000?????????1????????0?1??01?????0???1???0?????1???0???????0?????1?1?0??0???????01????????0???1???0??0???0?????????????????1??????1???10??1010???...

output:

679474848

result:

ok "679474848"

Test #28:

score: 0
Accepted
time: 209ms
memory: 18564kb

input:

456
?????0???????????????0?????1???????0???1??????????????????1??????1?????????????1??????1??????????0??????????????1????????????????????1??????????1???0???0??1???1????????00??0?????1???0?????????????1?0??1??1?1???0???1????????????0???????????????0?0??0?????0????????01?????????????????????????????10...

output:

920943116

result:

ok "920943116"

Test #29:

score: 0
Accepted
time: 243ms
memory: 19048kb

input:

484
????????????????????????????????0????1???1???????1????????1?????????0?????1??1??????????????????????1???????01???????????????????1??1???????????????1?1?0?0??1????????1??1???????????????????????????0?????????????0?????????????1????0??????1?????????0?0??????????1????????????1??????????????????????...

output:

453361220

result:

ok "453361220"

Test #30:

score: 0
Accepted
time: 183ms
memory: 17916kb

input:

448
?1?01??1????01?10????1???0????????????10????0??????1????1??????1?????1?0??1????101?1????1??????????????0?????1???0???????01?0?1?1????1???1?01?????????????0?1???1???01????0???????????????1??????01?1??????1?1?1??0???0?????????1????????1??1?0?1?0???????????????1?????1???0?0?????0????0??0???????????...

output:

84175678

result:

ok "84175678"

Test #31:

score: 0
Accepted
time: 244ms
memory: 18168kb

input:

480
?0?????????????????????0???00???1???0?????1?????????1??????????1?????1????????0??????????1????0???10?????????1????1????0?????0???01??????????0?????0???0?????????0???????01??????????????0????????0?????1????1?0??0?0????????????????1???1??01????????????1????0??????0??????1??1???????????????????????...

output:

247404334

result:

ok "247404334"

Test #32:

score: 0
Accepted
time: 249ms
memory: 18936kb

input:

492
??????00??????0??0??????????1???1?1?010????????????????????00???1???0?????0???????1?????????0???????1?????????????1???10???0?????????????????0??????????????0??????1???0????0?0???0??100?0?????????1??1????1???????????1????1??0?????????00??????1??1??????1????01?1?0??????0???????1????????????1??0???...

output:

487405442

result:

ok "487405442"

Test #33:

score: 0
Accepted
time: 211ms
memory: 18164kb

input:

456
????1???????????1???1????0????????????????????????????????????1???????0?????1???1?1??????????????????????????1?????????1?00??????????10?0????????????1??????????1?0????????1?1?????????????????0??????0???????1???????????????????????????0????????0??????1??????????0??1???????????????????????????????...

output:

884555628

result:

ok "884555628"

Test #34:

score: 0
Accepted
time: 222ms
memory: 18348kb

input:

460
??????1????1??????????0??0?????????????????0?????0???????????1?????????????1???????????01???????0????????????0???0???????????????????????????1???0????0??????????0??0??????1????0???????????????01?????????????0???????????????????????????????1????0????0????1??????1???????1???0??????????????????????...

output:

244536851

result:

ok "244536851"

Test #35:

score: 0
Accepted
time: 202ms
memory: 18424kb

input:

456
???????1?1????????????????00??????????1??1?0???????0??????0??????????0??1?????0??1???0?1??1?1?1???00?10?0???01??????????????0???01?0??000?1????1????????0????1?1????1???01???0?????1?0??????????1???0???1?1??????????01???1?????0???????0?1????1???1?0??0????1????0?0??1????????????0???0?????0??????01?...

output:

890392505

result:

ok "890392505"

Extra Test:

score: 0
Extra Test Passed