QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#668010 | #9489. 0100 Insertion | fryan | WA | 0ms | 3608kb | C++17 | 1.5kb | 2024-10-23 10:37:33 | 2024-10-23 10:37:33 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
#define i64 int64_t
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
const int mod = 998244353;
const int mxn = 51;
int n,s[mxn];
i64 dp[mxn][4*mxn][mxn][2];
/*
0 : 1
1 : -3
dp[i][j][k] = prefix sum is n+i, prefix min is -j, last character is k
*/
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin>>n;
for (int i=0; i<n; i++) {
char c; cin>>c;
if (c=='?') s[i]=2;
else s[i]=c-'0';
}
reverse(s,s+n);
for (int i=0; i<n; i++) {
cout<<s[i];
}
// cout<<"\n\n";
dp[0][n][0][0] = 1;
for (int i=0; i<=n; i++) {
for (int j=0; j<4*n; j++) {
for (int k=0; k<mxn; k++) {
if (dp[i][j][k][0] || dp[i][j][k][1]) {
// cout<<i<<" "<<j<<" "<<k<<" 0: "<<dp[i][j][k][0]<<"\n";
// cout<<i<<" "<<j<<" "<<k<<" 1: "<<dp[i][j][k][1]<<"\n\n";
} else {
continue;
}
if (s[i]==0 || s[i]==2) {
dp[i+1][j+1][k][0] += dp[i][j][k][0];
dp[i+1][j+1][k][0] += dp[i][j][k][1];
dp[i+1][j+1][k][0] %= mod;
}
if (s[i]==1 || s[i]==2) {
// cout<<i<<"~\n";
if (i==n-1 || i==1 || i==0) continue;
int pfx = j-3-n;
int pmn = -k;
if (pfx+1 < pmn) continue;
dp[i+1][j-3][max(n-j+3,k)][1] += dp[i][j][k][0];
dp[i+1][j-3][max(n-j+3,k)][1] %= mod;
}
}
}
}
int res=0;
for (int i=0; i<n; i++) {
res += dp[n][n][i][0];
res %= mod;
}
cout<<res;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3608kb
input:
8 0??0?100
output:
001202202
result:
wrong answer 1st words differ - expected: '2', found: '001202202'