QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#766753 | #9489. 0100 Insertion | konyakest | ML | 1ms | 9312kb | C++17 | 1.8kb | 2024-11-20 18:30:30 | 2024-11-20 18:30:31 |
Judging History
answer
#include<bits/stdc++.h>
#define F(i,j,k) for(auto i=j;i<=(decltype(i))k;i++)
#define x first
#define y second
#define exec(...) [&](){__VA_ARGS__}()
#define endl '\n'
#define os ostream
#define pb push_back
#define view(x) begin(x),end(x)
#define lambda [&]
using namespace std;
using ll=long long;
template<typename T>void ckmin(T& x,T y){x=min(x,y);}
template<typename T>void ckmax(T& x,T y){x=max(x,y);}
#ifdef DEBUG
template<typename T1,typename T2>os& operator<<(os&,pair<T1,T2>);
template<typename T,typename=decltype(T().begin()),typename=enable_if_t<!is_same_v<decay_t<T>,string>>>os& operator<<(os& out,T x){auto n=0u;out<<"{";for(auto i:x) out<<i<<(++n==x.size()?"":",");return out<<"}";}
template<typename ...T>os& operator<<(os& out,tuple<T...> x){return apply(lambda(T... x){auto n=0u;out<<"{";((out<<x<<(++n==sizeof...(T)?"":",")),...);},x),out<<"}";}
template<typename T1,typename T2>os& operator<<(os& out,pair<T1,T2> x){return out<<tuple(x);}
#define debug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<" = "<<std::make_tuple(__VA_ARGS__)<<endl
#else
#define debug(...) (void)0
#endif
const int maxn=505,mod=998244353;
int n;
char s[maxn];
int dp[maxn][maxn][maxn+maxn][2];
signed main(){
#if not defined(DEBUG) and 0
#define FILENAME
[](...){}(freopen(FILENAME ".in","r",stdin),freopen(FILENAME ".out","w",stdout));
#endif
cin.tie(0)->sync_with_stdio(0);
cin>>n>>(s+1);
dp[n+1][0][0+maxn][0]=1;
for(int i=n;i>=1;i--) F(j,0,n) F(k,-n,n) if(dp[i+1][j][k+maxn]){
if(s[i]!='1')
(dp[i][j][k-1+maxn][0]+=(dp[i+1][j][k+maxn][0]+dp[i+1][j][k+maxn][1])%mod)%=mod;
if(i!=1&&i!=n&&s[i]!='0'&&max(j,k+3)<=j+1)
(dp[i][max(j,k+3)][k+3+maxn][1]+=dp[i+1][j][k+maxn][0])%=mod;
}
int ans=0;
F(i,0,n) (ans+=dp[1][i][maxn][0])%=mod;
cout<<ans<<endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5976kb
input:
8 0??0?100
output:
2
result:
ok "2"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5748kb
input:
4 ?10?
output:
1
result:
ok "1"
Test #3:
score: 0
Accepted
time: 0ms
memory: 9312kb
input:
28 ???????????0???0??????1???0?
output:
2023
result:
ok "2023"
Test #4:
score: 0
Accepted
time: 1ms
memory: 5684kb
input:
4 ????
output:
1
result:
ok "1"
Test #5:
score: 0
Accepted
time: 1ms
memory: 5904kb
input:
8 11111111
output:
0
result:
ok "0"
Test #6:
score: -100
Memory Limit Exceeded
input:
500 ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
870731023