QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#764383 | #9489. 0100 Insertion | L_Wave | AC ✓ | 70ms | 14568kb | C++20 | 2.1kb | 2024-11-20 08:55:12 | 2024-11-20 08:55:12 |
Judging History
answer
// Problem: # 9489. 0100 Insertion
// Author: XZC(L_Wave)
// Language: Cpp/G++20
// Contest:
// URL: https://qoj.ac/problem/9489
// Memory Limit: 1024 MB
// Time Limit: 1000 ms
// Create Time: not 2024-11-20 08:41:35, but 1926-08-17 11:45:14
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a), i##ABRACADABRA = (b); i <= i##ABRACADABRA; i++)
#define drep(i, a, b) for (int i = (a), i##ABRACADABRA = (b); i >= i##ABRACADABRA; i--)
using namespace std;
using ll = long long;
constexpr ll mod=998244353;
template<typename T,int B>
class dArray{
static_assert(B>=0,"dArray size must not be negative");
T a[B+B+10];
public:
T&operator[](int x){
assert(-B<=x&&x<=B);
return a[x+B+5];
}
T operator[](int x)const{
assert(-B<=x&&x<=B);
return a[x+B+5];
}
void read(){
rep(i,-B,B)cin>>a[i+B+5];
}
void read(int L,int R){
assert(-B<=L&&L<=B);
assert(-B<=R&&R<=B);
rep(i,L,R)cin>>a[i+B+5];
}
void print(char sep=' ',char end='\n')const{
rep(i,-B,B)cout<<a[i+B+5]<<(i==B?end:sep);
}
void print(int L,int R,char sep=' ',char end='\n')const{
assert(-B<=L&&L<=B);
assert(-B<=R&&R<=B);
rep(i,L,R)cout<<a[i+B+5]<<(i==B?end:sep);
}
};
dArray<ll,505>dp[2][2][505];
int n;
ll res;
char s[505];
int main() {
scanf("%d%s",&n,s+1);
reverse(s+1,s+n+1);
dp[0][0][0][0]=1;
rep(i,1,n){
rep(v,0,1)rep(j,0,i/3+1)rep(k,-i,j)dp[i&1][v][j][k]=0;
if (s[i]!='0'){
// Place 1
rep(j,0,(i-1)/3+1)rep(k,-i+1,j)
if (k+2<=j)(dp[i&1][1][max(j,k+3)][k+3]+=dp[(i-1)&1][0][j][k])%=mod;
}
if (s[i]!='1'){
// Place 0
// cout<<(i-1)/3+1<<'\n';
rep(j,0,(i-1)/3+1)rep(k,-i+1,j){
(dp[i&1][0][j][k-1]+=dp[(i-1)&1][1][j][k]+dp[(i-1)&1][0][j][k])%=mod;
// cout<<j<<' '<<k<<'\n';
}
}
// rep(j,0,i/3+1)rep(k,-i,j)cout<<i<<' '<<j<<' '<<k<<' '<<dp[i&1][0][j][k]<<' '<<dp[i&1][1][j][k]<<'\n';
}
rep(i,0,n/3+1)(res+=dp[n&1][0][i][0])%=mod;
printf("%lld\n",res);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 10068kb
input:
8 0??0?100
output:
2
result:
ok "2"
Test #2:
score: 0
Accepted
time: 0ms
memory: 7896kb
input:
4 ?10?
output:
1
result:
ok "1"
Test #3:
score: 0
Accepted
time: 1ms
memory: 8084kb
input:
28 ???????????0???0??????1???0?
output:
2023
result:
ok "2023"
Test #4:
score: 0
Accepted
time: 1ms
memory: 7900kb
input:
4 ????
output:
1
result:
ok "1"
Test #5:
score: 0
Accepted
time: 1ms
memory: 10020kb
input:
8 11111111
output:
0
result:
ok "0"
Test #6:
score: 0
Accepted
time: 68ms
memory: 12668kb
input:
500 ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
870731023
result:
ok "870731023"
Test #7:
score: 0
Accepted
time: 65ms
memory: 13888kb
input:
500 ???????????????????0???????????????????????????????????????0??????????????????????1???????????????????????????????????????00????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????1???????????????????????????????????...
output:
763641704
result:
ok "763641704"
Test #8:
score: 0
Accepted
time: 22ms
memory: 11464kb
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: 0ms
memory: 10708kb
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: 7ms
memory: 8844kb
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: 18ms
memory: 9256kb
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: 14ms
memory: 13312kb
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: 25ms
memory: 9864kb
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: 2ms
memory: 8728kb
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: 2ms
memory: 8572kb
input:
116 ???????????????????????????????01?1???????????????0?00????0?????????????????1?0?????????????????1???????????????00??
output:
717954632
result:
ok "717954632"
Test #16:
score: 0
Accepted
time: 8ms
memory: 9124kb
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: 7ms
memory: 9368kb
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: 62ms
memory: 14568kb
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: 70ms
memory: 14440kb
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: 62ms
memory: 14548kb
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: 8452kb
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: 8136kb
input:
24 ?0?0?????0??????????????
output:
587
result:
ok "587"
Test #23:
score: 0
Accepted
time: 1ms
memory: 8452kb
input:
76 ?????0?????????????????0????????????????????????????1???0???????????????????
output:
83575746
result:
ok "83575746"
Test #24:
score: 0
Accepted
time: 1ms
memory: 8092kb
input:
28 00???0???0?0??0???0???0?????
output:
859
result:
ok "859"
Test #25:
score: 0
Accepted
time: 0ms
memory: 10204kb
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: 47ms
memory: 10280kb
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: 49ms
memory: 14416kb
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: 52ms
memory: 10408kb
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: 56ms
memory: 14496kb
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: 44ms
memory: 11520kb
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: 57ms
memory: 14452kb
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: 64ms
memory: 12612kb
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: 48ms
memory: 10456kb
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: 50ms
memory: 12500kb
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: 50ms
memory: 14200kb
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