QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#407197#8639. 消除Crysfly100 ✓20ms4772kbC++173.0kb2024-05-08 10:25:282024-05-08 10:25:29

Judging History

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

  • [2024-05-08 10:25:29]
  • 评测
  • 测评结果:100
  • 用时:20ms
  • 内存:4772kb
  • [2024-05-08 10:25:28]
  • 提交

answer

// what is matter? never mind. 
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2") 
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
//#define int long long
#define ull unsigned long long
#define SZ(x) ((int)((x).size()))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
inline int read()
{
    char c=getchar();int x=0;bool f=0;
    for(;!isdigit(c);c=getchar())f^=!(c^45);
    for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
    if(f)x=-x;return x;
}

#define mod 998244353
struct modint{
	int x;
	modint(int o=0){x=o;}
	modint &operator = (int o){return x=o,*this;}
	modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
	modint &operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;}
	modint &operator *=(modint o){return x=1ll*x*o.x%mod,*this;}
	modint &operator ^=(int b){
		modint a=*this,c=1;
		for(;b;b>>=1,a*=a)if(b&1)c*=a;
		return x=c.x,*this;
	}
	modint &operator /=(modint o){return *this *=o^=mod-2;}
	friend modint operator +(modint a,modint b){return a+=b;}
	friend modint operator -(modint a,modint b){return a-=b;}
	friend modint operator *(modint a,modint b){return a*=b;}
	friend modint operator /(modint a,modint b){return a/=b;}
	friend modint operator ^(modint a,int b){return a^=b;}
	friend bool operator ==(modint a,modint b){return a.x==b.x;}
	friend bool operator !=(modint a,modint b){return a.x!=b.x;}
	bool operator ! () {return !x;}
	modint operator - () {return x?mod-x:0;}
	bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,int y){return x^y;}

vector<modint> fac,ifac,iv;
inline void initC(int n)
{
	if(iv.empty())fac=ifac=iv=vector<modint>(2,1);
	int m=iv.size(); ++n;
	if(m>=n)return;
	iv.resize(n),fac.resize(n),ifac.resize(n);
	For(i,m,n-1){
		iv[i]=iv[mod%i]*(mod-mod/i);
		fac[i]=fac[i-1]*i,ifac[i]=ifac[i-1]*iv[i];
	}
}
inline modint C(int n,int m){
	if(m<0||n<m)return 0;
	return initC(n),fac[n]*ifac[m]*ifac[n-m];
}
inline modint sign(int n){return (n&1)?(mod-1):(1);}

#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;

#define maxn 2000005
#define inf 0x3f3f3f3f

int n;
char s[maxn];
modint sf[4][2],f[4][2];

/*
B XX XX .. X
X AB XX .. X
..
X XX .. AB X
X XX XX .. A

done
X .. .
X B. .
X A. .
*/

signed main()
{
	// ?0 1? , no 01
	n=read(),scanf("%s",s+1);
	sf[3][0]=1;
	For(i,1,n){
		memset(f,0,sizeof f);
		if(s[i]!='1'){
			For(c,0,1){
				f[0][!c]+=sf[0][c];
				f[3][!c]+=sf[1][c];
				f[1][!c]+=sf[2][c]+sf[3][c];
			}
		}
		if(s[i]!='0'){
			For(c,0,1){
				f[0][!c]+=sf[0][c];
				f[2][!c]+=sf[1][c];
				f[1][!c]+=sf[2][c];
				f[0][!c]+=sf[3][c];
			}
		}
		For(j,0,3) For(c,0,1) sf[j][c]+=f[j][c];
	}
	modint res=sf[0][0]+sf[3][0];
	cout<<res.x;
	return 0;
}
/*

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 5
Accepted
time: 0ms
memory: 3752kb

input:

8
????????

output:

2764

result:

ok 1 number(s): "2764"

Test #2:

score: 5
Accepted
time: 1ms
memory: 3632kb

input:

8
100?011?

output:

240

result:

ok 1 number(s): "240"

Test #3:

score: 5
Accepted
time: 1ms
memory: 3744kb

input:

4997
??????1???????????????????1????????????????????????????????????????0?????????01???0????????????????????????1??1?????0???1?1????????????0????0?????????????????????????????0???0??????????0?????1100????0??1???????????1????????????????????????1??000??????????????????????????????0????????????0?????1...

output:

481706525

result:

ok 1 number(s): "481706525"

Test #4:

score: 5
Accepted
time: 1ms
memory: 3780kb

input:

4999
011???1011?10?1?00010?10??01?010?00?0?0??0100?010001001???10??00000110001?0??010??10??0?0??0?00??11001011011??11?11?1?11?1???0?1?1??0?1?00100?1011001111101011?101001?0???000?11111010?0010?0000?1111000?01?10???0?1001?1?11????010?1?0?0??10111?1?011??0111111?00???0??0?111??10???0???0?1?00010?1?010...

output:

927141779

result:

ok 1 number(s): "927141779"

Test #5:

score: 5
Accepted
time: 1ms
memory: 3636kb

input:

4998
?1?1???1???0???1???1?1????????0???????????????????????????0??????????????????????10???????????????????????0??1???????0??0???????1???????1?10?????????????????0?0???????00?1?????0???????????0????????0???????????1??1?????0???????????????????????????????0??????????1?????????????????????????????????...

output:

527991571

result:

ok 1 number(s): "527991571"

Test #6:

score: 5
Accepted
time: 1ms
memory: 3776kb

input:

5000
100?011?00101?0?010?010110??1000?1?01111?0?1?011?11011???101?11?0?110?10?0?01011??10?01??10100?0?0???00?10??11011111?001101?000?00000101?0?01?10?11111110?11?1?01?1?11?01??111?10?101??11011?0?100?11?01100?1???10?1010?110110110011???0?00000??1?111?0001??101?0?10?111?0?00?0?0?011?111111?0000?1010?...

output:

775395392

result:

ok 1 number(s): "775395392"

Test #7:

score: 5
Accepted
time: 1ms
memory: 3520kb

input:

4997
??????1???????????????????1????????????????????????????????????????0?????????01???0????????????????????????1??1?????0???1?1????????????0????0?????????????????????????????0???0??????????0?????1100????0??1???????????1????????????????????????1??000??????????????????????????????0????????????0?????1...

output:

481706525

result:

ok 1 number(s): "481706525"

Test #8:

score: 5
Accepted
time: 1ms
memory: 3528kb

input:

5000
100?011?00101?0?010?010110??1000?1?01111?0?1?011?11011???101?11?0?110?10?0?01011??10?01??10100?0?0???00?10??11011111?001101?000?00000101?0?01?10?11111110?11?1?01?1?11?01??111?10?101??11011?0?100?11?01100?1???10?1010?110110110011???0?00000??1?111?0001??101?0?10?111?0?00?0?0?011?111111?0000?1010?...

output:

775395392

result:

ok 1 number(s): "775395392"

Test #9:

score: 5
Accepted
time: 1ms
memory: 3712kb

input:

4999
?1?1???1???0???1???1?1????????0???????????????????????????0??????????????????????10???????????????????????0??1???????0??0???????1???????1?10?????????????????0?0???????00?1?????0???????????0????????0???????????1??1?????0???????????????????????????????0??????????1?????????????????????????????????...

output:

356481180

result:

ok 1 number(s): "356481180"

Test #10:

score: 5
Accepted
time: 0ms
memory: 3716kb

input:

4998
011???1011?10?1?00010?10??01?010?00?0?0??0100?010001001???10??00000110001?0??010??10??0?0??0?00??11001011011??11?11?1?11?1???0?1?1??0?1?00100?1011001111101011?101001?0???000?11111010?0010?0000?1111000?01?10???0?1001?1?11????010?1?0?0??10111?1?011??0111111?00???0??0?111??10???0???0?1?00010?1?010...

output:

300686604

result:

ok 1 number(s): "300686604"

Test #11:

score: 5
Accepted
time: 15ms
memory: 4720kb

input:

999996
????1??100??????????1?1??????????????????????????????1???????????1?1??????1?????0???????????????10????????????1????????????????????????????????0????????0??1??????????????????????0???1100??01????1????????????????0?0???0???????????????????????1?1???????0???1????????????????0???????????????????1...

output:

775312388

result:

ok 1 number(s): "775312388"

Test #12:

score: 5
Accepted
time: 18ms
memory: 4716kb

input:

999999
01?1??1?1??0000111?1?0???1000011?10?1?1??10010???10?011????0?1?000??0110??10?00?0111000001100001100?1?001111?1??1101???01101?101?010011??01??0?1?00?0??1010101?0?11??01?111111010011011?0100000?10010?0?0?10??1??001??00100?0??1?0?00001?11??1111001?0110?111??1????0?11?00110000110?000011?0??0?100?...

output:

240432497

result:

ok 1 number(s): "240432497"

Test #13:

score: 5
Accepted
time: 19ms
memory: 4712kb

input:

999998
???????????0????10??1?????????1???????????????????????1??????1????0?????10????????0??0???0?1??????0???1?????1???0???????????0???????11??????????1????0?????????0????0???????0????01?0?????????????0???????10??????1????????1??1?0?1??????????????1????????????1?1????????????????????????????????????...

output:

447215377

result:

ok 1 number(s): "447215377"

Test #14:

score: 5
Accepted
time: 13ms
memory: 4724kb

input:

999998
01?1??1?1??0000111?1?0???1000011?10?1?1??10010???10?011????0?1?000??0110??10?00?0111000001100001100?1?001111?1??1101???01101?101?010011??01??0?1?00?0??1010101?0?11??01?111111010011011?0100000?10010?0?0?10??1??001??00100?0??1?0?00001?11??1111001?0110?111??1????0?11?00110000110?000011?0??0?100?...

output:

149098020

result:

ok 1 number(s): "149098020"

Test #15:

score: 5
Accepted
time: 19ms
memory: 4692kb

input:

1000000
?????0????????11???0???1?????1??????0???????0?1??101???????????0????????????????????1?????????????0?????????????????1????????????????1???????1????????????????0????????????????????????????????00????????1???1???????10????1???10?1?????1?????????????0?1??0?????0????????????????1??????????0??????...

output:

934928332

result:

ok 1 number(s): "934928332"

Test #16:

score: 5
Accepted
time: 18ms
memory: 4668kb

input:

999996
10????11?0??1?010??1?1?101??111?111?0100??00?0??01?0??11101?0???0111??1???1?0011?11?00011?1?101??01?00??011011?1?0?1000?0?1??1???10?101?1100????0?0??11?11?1??11111?100010011011?10?00?11?01110?010??10110???1?10?11?1010000?000?10??01?11?001?1?0????11011?0?001001010?01?1????11?0101??0?01010111?1...

output:

859594688

result:

ok 1 number(s): "859594688"

Test #17:

score: 5
Accepted
time: 20ms
memory: 4492kb

input:

999997
????1??100??????????1?1??????????????????????????????1???????????1?1??????1?????0???????????????10????????????1????????????????????????????????0????????0??1??????????????????????0???1100??01????1????????????????0?0???0???????????????????????1?1???????0???1????????????????0???????????????????1...

output:

77832459

result:

ok 1 number(s): "77832459"

Test #18:

score: 5
Accepted
time: 11ms
memory: 4752kb

input:

999999
0000110000100?0?1000?100001?100?11?00?111?11?100?0110??001???110?0000111?0?111?01?01?00?10111??1011000??0?110?0010?10?001?????1?000110010011?1?1???0?011011?10?1000?1?1???1?110110111101??10?000100??1??11100?1?000111?101????010010?1010?100??0?00??01??00101?1?1110?00011011111101?1?1??001010?0?01...

output:

853633847

result:

ok 1 number(s): "853633847"

Test #19:

score: 5
Accepted
time: 16ms
memory: 4724kb

input:

1000000
?????0????????11???0???1?????1??????0???????0?1??101???????????0????????????????????1?????????????0?????????????????1????????????????1???????1????????????????0????????????????????????????????00????????1???1???????10????1???10?1?????1?????????????0?1??0?????0????????????????1??????????0??????...

output:

934928332

result:

ok 1 number(s): "934928332"

Test #20:

score: 5
Accepted
time: 18ms
memory: 4772kb

input:

999999
0000110000100?0?1000?100001?100?11?00?111?11?100?0110??001???110?0000111?0?111?01?01?00?10111??1011000??0?110?0010?10?001?????1?000110010011?1?1???0?011011?10?1000?1?1???1?110110111101??10?000100??1??11100?1?000111?101????010010?1010?100??0?00??01??00101?1?1110?00011011111101?1?1??001010?0?01...

output:

853633847

result:

ok 1 number(s): "853633847"