QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#827175 | #9489. 0100 Insertion | hhiron | WA | 29ms | 39428kb | C++14 | 2.0kb | 2024-12-22 20:08:38 | 2024-12-22 20:08:39 |
Judging History
answer
#include<bits/stdc++.h>
#define INF 0x7fffffff
#define int long long
typedef long long ll;
using namespace std;
const int N=1100;
const int MOD=998244353;
int n,f[2][N][N][2];
string s;
void add(int &x,int y){
x=(x+y)%MOD;
return;
}
signed main(){
cin>>n>>s;
s=" "+s;
for(int i=1;i<=n/2;i++) swap(s[i],s[n-i+1]);
f[0][500][500][0]=1;cout<<s<<endl;
int tag=0;
for(int i=1;i<=n;i++){
tag=i&1;
for(int j=0;j<=1005;j++) for(int k=0;k<=1005;k++) f[tag][j][k][0]=f[tag][j][k][1]=0;
if(s[i]=='?'){
for(int j=0;j<=1000;j++){
for(int k=j;k<=1000;k++){
if(k>=j+2) add(f[tag][j+3][max(j+3,k)][1],f[tag^1][j][k][0]);
if(j-1>=0){
add(f[tag][j-1][k][0],f[tag^1][j][k][1]);
add(f[tag][j-1][k][0],f[tag^1][j][k][0]);
}
}
}
}else{
int lrc=0;
if(s[i]=='0') lrc=-1;
else lrc=3;
for(int j=0;j<=1000;j++){
if(j+lrc<0) continue;
for(int k=j;k<=1000;k++){
if(s[i]=='0'){
add(f[tag][j+lrc][max(j+lrc,k)][0],f[tag^1][j][k][1]);
add(f[tag][j+lrc][max(j+lrc,k)][0],f[tag^1][j][k][0]);
//if(f[tag][j+lrc][max(j+lrc,k)][0]) cout<<i<<" "<<j<<" "<<k<<" "<<f[tag^1][j][k][0]<<" "<<j+lrc<<" "<<max(j+lrc,k)<<endl;
}else{
if(k>=j+2) add(f[tag][j+lrc][max(j+lrc,k)][1],f[tag^1][j][k][0]);
// if(f[tag][j+lrc][max(j+lrc,k)][1]) cout<<i<<" "<<j<<" "<<k<<" "<<f[tag^1][j][k][0]<<" "<<j+lrc<<" "<<max(j+lrc,k)<<endl;
}
}
}
}
}
int ans=0;
for(int i=500;i<=1000;i++) ans=(ans+f[tag][500][i][0])%MOD;
printf("%lld",ans);
return 0;
}
/*
4
0100
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 29ms
memory: 39428kb
input:
8 0??0?100
output:
001?0??0 2
result:
wrong answer 1st words differ - expected: '2', found: '001?0??0'