QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#767901#9489. 0100 InsertionReqCxmChtChrAC ✓1533ms37768kbC++143.9kb2024-11-20 22:36:402024-11-20 22:36:44

Judging History

你现在查看的是最新测评结果

  • [2024-11-20 22:36:44]
  • 评测
  • 测评结果:AC
  • 用时:1533ms
  • 内存:37768kb
  • [2024-11-20 22:36:40]
  • 提交

answer

#include<bits/stdc++.h>
//#pragma GCC optimize(3)
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define ll long long
#define ull unsigned ll
#define db double
#define ldb long db
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pbI push_back
#define inf 1e9
#define mdI int mid=(l+r)>>1
#define lowbit(x) (x&-x)
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define MAXN 520
#define gint __int128
#define MOD 998244353
int qread(){
	char o=getchar();int f=1,x=0;
	for(;!isdigit(o);o=getchar())if(o=='-')f*=-1;
	for(;isdigit(o);o=getchar())x=x*10+o-'0';
	return f*x;
}
void chmx(int &x,int y){if(y>x)x=y;}
void chmi(int &x,int y){if(y<x)x=y;}
bool FLA;
namespace MathPart{
	#define rep(a,b,c) for(int a=b;a<=c;a++)
	#define vep(a,b,c) for(int a=b;a>=c;a--)
	void exgcd(ll a,ll b,ll &x,ll &y){if(b==0){x=1,y=0;return;}exgcd(b,a%b,y,x);y-=(a/b)*x;}
	ll inv(ll a,ll p=MOD){ll x,y;exgcd(a,p,x,y);return (x+p)%p;}
	gint qp(ll a,ll b,ll p=MOD){gint rs=1,bs=a;while(b){if(b&1){rs=rs*bs%p;}bs=bs*bs%p;b>>=1;}return rs;}
	ll fac[MAXN],ifac[MAXN];
	void initF(ll n,ll p=MOD){
		fac[0]=1;rep(i,1,n){fac[i]=fac[i-1]*i%p;}
		ifac[n]=inv(fac[n],p);vep(i,n-1,0){ifac[i]=ifac[i+1]*(i+1)%p;}
	}
	ll C(ll n,ll m){if(n<m){return 0;}return fac[n]*ifac[m]%MOD*ifac[n-m]%MOD;}
	ll CC(ll n,ll m,ll p=MOD){ll rs=1;rep(i,0,m-1){rs=rs*(n-i)%p*inv(i+1,MOD)%p;}return rs;}
	ll S2OL(ll n,ll m){
		ll rs=0,d=1,f=1;
		for(ll k=0;k<=m;k++){
			rs=(rs+f*C(m,k)*qp(m-k,n,MOD)%MOD+MOD)%MOD;
			d=d*max(k,1ll)%MOD;f*=-1;
		}return rs*inv(d,MOD)%MOD;
	}
	ll phi(ll a){ll rs=a,m=sqrt(a);
		rep(i,2,m){if(a%i==0){rs=rs/i*(i-1);while(a%i==0){a/=i;}}}
		if(a>1){rs=rs/a*(a-1);}return rs;
	}
	bool MR(ll pr){if(pr<2)return 0;if(pr==3)return 1;if(pr==2)return 1;
		ll a=pr-1,b=0;while(!(a&1))a>>=1,b++;
		for(int i=1;i<=8;++i){
		    ll x=rand()%(pr-2)+2,v=qp(x,a,pr),j;if(v==1||v==pr-1)continue;
		    for(j=0;j<b-1;j++){v=(gint)v*v%pr;if(v==pr-1)break;}
			if(v!=pr-1)return 0;
		}return 1;
	}
}
//using namespace MathPart;
int dp[2][MAXN*2][MAXN*2][2];//i s_i max_{j=1}^i(s_i) [s_i=0/1]
int off=500;
int n;string S;
bool FLB;
signed main(){
	cerr<<((&FLB)-(&FLA))/1024.0/1024<<endl;
	cin>>n;cin>>S;
	reverse(S.begin(),S.end());S=" "+S;
	dp[0][off][off][0]=1;
	rep(i,0,n-1){
        bool s=i&1;
        memset(dp[!s],0,sizeof(dp[!s]));
        rep(j,0,off+off){
            rep(k,j,off+off){
                if(S[i+1]=='0'||S[i+1]=='?'){
                    if(j){
                        dp[!s][j-1][k][0]+=dp[s][j][k][0]+dp[s][j][k][1];
                        dp[!s][j][k][0]%=MOD;
                    }
                }
                if(S[i+1]=='1'||S[i+1]=='?'){
                    if(j+3<=2*off&&k>=j+2){
                        dp[!s][j+3][max(k,j+3)][1]+=dp[s][j][k][0];
                        dp[!s][j+3][max(k,j+3)][1]%=MOD;
                    }
                }
            }
        }
	}
	int ans=0;
	rep(i,0,2*off){ans+=dp[n&1][off][i][0];ans%=MOD;}cout<<ans;
}
/*
8
0??0?100
由判定性问题展开
处理01序列的经典方法:设定数码的权值,直观折线图
(找到对目前判定方法的反例:0010问题)
下文s表示前缀和
0=-1,1=+3
对于一个1他不能匹配因为他右边下不去,
翻转一下,左边下不去导致的,
充要条件:无相邻1,最后非1,和=0,每一个i处的1,存在一个j使得s_j=s_i-1(知其下降过程连续,实际上和最大值等价)
必要性:递归构造可得
充分性:取第一个最大的s_i(一定为1),由条件知s_{i-1}=s_i-3,s_{i-2}=s_i-2,找到如是j(j最小),s_{i+1}=s_i-1,s_{i+2}=s_i-2(最大性)
观察[j+1,i-1]平的,j+2向下(否则没有最小性),找到(j+1,j+2,i,i+1)这一组,随后可以删除、拼接、归纳


跳出区间dp套路
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 24ms
memory: 37708kb

input:

8
0??0?100

output:

2

result:

ok "2"

Test #2:

score: 0
Accepted
time: 14ms
memory: 37584kb

input:

4
?10?

output:

1

result:

ok "1"

Test #3:

score: 0
Accepted
time: 77ms
memory: 37620kb

input:

28
???????????0???0??????1???0?

output:

2023

result:

ok "2023"

Test #4:

score: 0
Accepted
time: 11ms
memory: 37612kb

input:

4
????

output:

1

result:

ok "1"

Test #5:

score: 0
Accepted
time: 16ms
memory: 37760kb

input:

8
11111111

output:

0

result:

ok "0"

Test #6:

score: 0
Accepted
time: 1385ms
memory: 37700kb

input:

500
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...

output:

870731023

result:

ok "870731023"

Test #7:

score: 0
Accepted
time: 1380ms
memory: 37640kb

input:

500
???????????????????0???????????????????????????????????????0??????????????????????1???????????????????????????????????????00????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????1???????????????????????????????????...

output:

763641704

result:

ok "763641704"

Test #8:

score: 0
Accepted
time: 951ms
memory: 37708kb

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: 409ms
memory: 37700kb

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: 595ms
memory: 37760kb

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: 866ms
memory: 37640kb

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: 865ms
memory: 37692kb

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: 1037ms
memory: 37768kb

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: 264ms
memory: 37708kb

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: 293ms
memory: 37608kb

input:

116
???????????????????????????????01?1???????????????0?00????0?????????????????1?0?????????????????1???????????????00??

output:

717954632

result:

ok "717954632"

Test #16:

score: 0
Accepted
time: 759ms
memory: 37612kb

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: 683ms
memory: 37704kb

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: 1379ms
memory: 37636kb

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: 1324ms
memory: 37672kb

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: 1285ms
memory: 37676kb

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: 196ms
memory: 37684kb

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: 60ms
memory: 37644kb

input:

24
?0?0?????0??????????????

output:

587

result:

ok "587"

Test #23:

score: 0
Accepted
time: 196ms
memory: 37756kb

input:

76
?????0?????????????????0????????????????????????????1???0???????????????????

output:

83575746

result:

ok "83575746"

Test #24:

score: 0
Accepted
time: 75ms
memory: 37760kb

input:

28
00???0???0?0??0???0???0?????

output:

859

result:

ok "859"

Test #25:

score: 0
Accepted
time: 118ms
memory: 37704kb

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: 1140ms
memory: 37672kb

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: 1352ms
memory: 37676kb

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: 1259ms
memory: 37708kb

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: 1436ms
memory: 37636kb

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: 1253ms
memory: 37672kb

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: 1397ms
memory: 37708kb

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: 1533ms
memory: 37688kb

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: 1225ms
memory: 37712kb

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: 1222ms
memory: 37672kb

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: 1177ms
memory: 37608kb

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