QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#739160 | #9489. 0100 Insertion | rqoi031 | RE | 0ms | 1700kb | C++20 | 2.2kb | 2024-11-12 21:03:13 | 2024-11-12 21:03:17 |
Judging History
answer
#include<stdio.h>
#include<algorithm>
typedef unsigned int uint;
typedef unsigned long long ull;
constexpr uint mod{998244353};
constexpr uint plus(const uint &x,const uint &y) {
if(x+y>=mod) {
return x+y-mod;
}
return x+y;
}
constexpr void add(uint &x,const uint &y) {
x=plus(x,y);
}
constexpr int N{500};
char str[N+5];
uint dp[2][(N>>2)+5][(N>>1)+(N>>2)+5][2];
int main() {
int n;
scanf("%d%s",&n,str+1);
std::reverse(str+1,str+n+1);
for(int i=0;i<=n>>2;i++) {
for(int j=0;j<=(n>>1)+(n>>2);j++) {
dp[0][i][j][0]=dp[0][i][j][1]=0;
}
}
const int shift((n>>1)+1);
dp[0][0][shift][0]=1;
for(int i=1;i<=n;i++) {
const int lim0(std::min(i/3,n>>2));
const int lim1(std::min((n>>1)+(n>>2),i));
for(int j=0;j<=lim0;j++) {
for(int k=-lim1;k<=lim0;k++) {
dp[1][j][shift+k][0]=dp[1][j][shift+k][1]=0;
}
}
if(str[i]!='1') {
for(int j=0;j<=lim0;j++) {
for(int k=-lim1;k<=lim0;k++) {
if(dp[0][j][shift+k][0]) {
add(dp[1][j][shift+k-1][0],dp[0][j][shift+k][0]);
}
if(dp[0][j][shift+k][1]) {
add(dp[1][j][shift+k-1][0],dp[0][j][shift+k][1]);
}
}
}
}
if(str[i]!='0') {
for(int j=0;j<=lim0;j++) {
for(int k=-lim1;k<=lim0&&k+3<=j;k++) {
if(dp[0][j][shift+k][0]) {
add(dp[1][j][shift+k+3][1],dp[0][j][shift+k][0]);
}
}
if(dp[0][j][shift+(j-2)][0]) {
add(dp[1][j+1][shift+j+1][1],dp[0][j][shift+(j-2)][0]);
}
}
}
for(int j=0;j<=lim0;j++) {
for(int k=-lim1;k<=lim0;k++) {
dp[0][j][shift+k][0]=dp[1][j][shift+k][0];
dp[0][j][shift+k][1]=dp[1][j][shift+k][1];
}
}
}
uint ans(0);
for(int i=0;i<=n>>2;i++) {
add(ans,dp[0][i][shift][0]);
}
printf("%u\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 1608kb
input:
8 0??0?100
output:
2
result:
ok "2"
Test #2:
score: 0
Accepted
time: 0ms
memory: 1604kb
input:
4 ?10?
output:
1
result:
ok "1"
Test #3:
score: 0
Accepted
time: 0ms
memory: 1700kb
input:
28 ???????????0???0??????1???0?
output:
2023
result:
ok "2023"
Test #4:
score: 0
Accepted
time: 0ms
memory: 1640kb
input:
4 ????
output:
1
result:
ok "1"
Test #5:
score: 0
Accepted
time: 0ms
memory: 1616kb
input:
8 11111111
output:
0
result:
ok "0"
Test #6:
score: -100
Runtime Error
input:
500 ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...