QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#429755#6344. The Best Problem of 2021ushg8877WA 935ms35824kbC++143.2kb2024-06-02 20:27:402024-06-02 20:27:41

Judging History

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

  • [2024-06-02 20:27:41]
  • 评测
  • 测评结果:WA
  • 用时:935ms
  • 内存:35824kb
  • [2024-06-02 20:27:40]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD=998244353;
struct modint{
int x;
modint(int y=0){x=y;}
};
modint operator +(modint x,modint y){return modint(x.x+y.x>=MOD?x.x+y.x-MOD:x.x+y.x);}
modint operator -(modint x,modint y){return (x.x<y.x?x.x-y.x+MOD:x.x-y.x);}
modint operator ^(modint x,int y){ll a=x.x,r=1;while(y){if(y&1)r=r*a%MOD;a=a*a%MOD,y>>=1;}return modint(r);}
modint operator *(modint x,modint y){return modint(1ll*x.x*y.x%MOD);}
modint operator /(modint x,modint y){return x*(y^(MOD-2));}
modint operator /(modint x,int y){return x/modint(y);}
modint operator *(modint x,int y){return modint(1ll*x.x*y%MOD);}
void operator +=(modint &x,modint y){x=(x+y);}
const int MAXN=2005;
int n,m;
bitset<MAXN> bas[MAXN],fin;
modint f[MAXN][MAXN],g[MAXN][MAXN],h[MAXN];
modint pw2[MAXN],pwpw2[MAXN],fac2[MAXN],inf2[MAXN];
modint C2(int x,int y){return x<0||x>y?modint(0):inf2[x]*inf2[y-x]*fac2[y];}
modint sgn(int x){return (x&1)?modint(MOD-1):modint(1);}
int main(){
	ios::sync_with_stdio(false);
	// freopen("Otomachi_Una.in","r",stdin);
	// freopen("Otomachi_Una.out","w",stdout);
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		string s;cin>>s;
		bitset<MAXN> my;
		for(int i=1;i<=m;i++) my[i]=(s[m-i]=='1');
		bool flag=false;
		for(int j=m;j>=1;j--) if(my[j]){
			if(bas[j].any()) my^=bas[j];
			else{
				bas[j]=my;
				flag=true;
				break;
			}
		}
		if(!flag){
			cout<<0;
			return 0;
		}
	}
	for(int i=1;i<=m;i++) if(bas[i].any()){
		for(int j=1;j<i;j++) if(bas[i][j]&&bas[j].any()) bas[i]^=bas[j];
	}
	bitset<MAXN> my,et;
	string s;cin>>s;
	for(int i=1;i<=m;i++) my[i]=(s[m-i]=='1');
	int n0=0;
	for(int i=m;i>=1;i--) if(bas[i].any()){
		et^=bas[i];
		bool flag=true;
		for(int j=m;j>=1;j--) if(my[j]!=et[j]){
			flag=(my[j]>et[j]);
			break;
		}
		fin[n0++]=flag;
		if(!flag) et^=bas[i];
	}
	pw2[0]=fac2[0]=inf2[0]=modint(1);pwpw2[0]=modint(2);
	for(int i=1;i<MAXN;i++){
		pw2[i]=pw2[i-1]*2;
		fac2[i]=fac2[i-1]*(pw2[i]-modint(1));
		inf2[i]=inf2[i-1]/(pw2[i]-modint(1));
		pwpw2[i]=pwpw2[i-1]*pwpw2[i-1];
	}
	// f[i][j] 前 i 位当中已经选了 j 位,且未顶到,钦定 pos[n] 以选
	// g[i][j] 前 i 为当中已经选了 j 位,且顶到
	f[0][0]=modint(1);g[0][0]=modint(2);
	for(int i=0;i<n;i++) for(int j=0;j<=i;j++) if(f[i][j].x||g[i][j].x){
		// from f[i][j] or g[i][j]
		if(fin[n-1-i]){
			// 这个位置上有值 desu~
			if(i==n-1){
				g[i+1][j+1]+=g[i][j]*pw2[i-j]*pwpw2[j];
				continue;
			}
			// 不选,这位当前是 0
			g[i+1][j]+=f[i][j]*pwpw2[j]/2;
			f[i+1][j]+=f[i][j]/2;
			// 不选,这位当前是 1
			f[i+1][j]+=f[i][j]/2;
			g[i+1][j]+=g[i][j]/2;
			// 选!
			f[i+1][j+1]+=f[i][j]*pw2[i-j];
			g[i+1][j+1]+=g[i][j]*pw2[i-j]*pwpw2[j];
		}else{
			// 选!
			f[i+1][j+1]+=f[i][j]*pw2[i-j];
			g[i+1][j+1]+=g[i][j]*pw2[i-j];
			// 不选,这位当前是 1
			f[i+1][j]+=f[i][j]/2;
			g[i+1][j]+=f[i][j]/2;
			// 不选,当前这位是 0
			f[i+1][j]+=f[i][j]/2;
			g[i+1][j]+=g[i][j]/2;
		}
	}
	h[0]=2;
	for(int i=1;i<=n;i++) h[i]=g[n][i]+pwpw2[i]*C2(i,n-1);
	modint ans;
	// q- 二项式反演 desu~
	for(int i=0;i<=n;i++) ans+=h[i]*sgn(n-i)*(modint(2)^((n-i)*(n-i-1)/2));
	ans=ans/2;
	cout<<ans.x<<'\n';
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 35764kb

input:

4 4
0001
0010
0100
1000
1101

output:

7364

result:

ok 1 number(s): "7364"

Test #2:

score: 0
Accepted
time: 0ms
memory: 35320kb

input:

3 2
00
00
00
11

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 7ms
memory: 35088kb

input:

2 3
110
101
101

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 0ms
memory: 35088kb

input:

3 10
1111100110
0011110100
0101100001
1110000001

output:

38

result:

ok 1 number(s): "38"

Test #5:

score: 0
Accepted
time: 0ms
memory: 35500kb

input:

7 13
1000101001000
1000000010000
1010101011111
1001100100111
1111111101100
0101010101110
1101100010100
1000010011001

output:

744450298

result:

ok 1 number(s): "744450298"

Test #6:

score: 0
Accepted
time: 6ms
memory: 35316kb

input:

100 100
1111010111010001011111110010101001001101000000000000011000001100101000100011100011000000110000001010
1001001110111010100100010111100010111110101100101000010111001011111010111100111000000011101010100111
000011010111000100110100010010011101001111100110111000100101010001101100101011000111101101...

output:

19562313

result:

ok 1 number(s): "19562313"

Test #7:

score: 0
Accepted
time: 42ms
memory: 35408kb

input:

400 500
1011011011010010111110101001010011000100001111000111111111001111100010101011110011010010011100100100111111000111001110111100101010000000100100011011011001011100100000000100001100001010100010111000110011000100101001010110110100110101000011011011011100111110010100101000011001100000001100001000...

output:

681985268

result:

ok 1 number(s): "681985268"

Test #8:

score: 0
Accepted
time: 249ms
memory: 35416kb

input:

999 1997
011101110101100100111101100000000100001110010001010100011010111010101101011100001000010001110100110111101101010111010011101111011001011100110110101011111011000111101011011000010101100101001110000111010101111100000100100101110000111001010101110110000001111111100110110011110100101000011100011...

output:

435150194

result:

ok 1 number(s): "435150194"

Test #9:

score: 0
Accepted
time: 865ms
memory: 35808kb

input:

1901 2000
10000111000111010000000000100110001100110010011001101110001011000001011000010111101110111001111000010110110100010100010101011111011101100111010101010001010010111010001011000001011010100011000101101010001110111100000101110110011001101111101111000100001010011101011110001100110001100000111110...

output:

9254020

result:

ok 1 number(s): "9254020"

Test #10:

score: 0
Accepted
time: 935ms
memory: 35824kb

input:

1984 2000
11111101001011101001011011010011000001100000101000001001111000100010011011000110110110100000001100000000001111101001111010111110000000010000000111111001010111101101110000111110010111001011011111010010110001011100110101000110000100010100100101010111101100000011110010010100101011101001110110...

output:

870006511

result:

ok 1 number(s): "870006511"

Test #11:

score: 0
Accepted
time: 42ms
memory: 35624kb

input:

2000 2000
00010001100000101100000110010101010101110010001000000100010010110010001100110000001110100111010110100110101010101111011100001110100011001000010001000011100111010100110101000111010010010111001001101100100000101001111111001111101001000101001011101001010010010101011110111001101101101001001000...

output:

0

result:

ok 1 number(s): "0"

Test #12:

score: 0
Accepted
time: 0ms
memory: 35328kb

input:

11 11
10000000000
01000000000
00100000000
00010000000
00001000000
00000100000
00000010000
00000001000
00000000100
00000000010
00000000001
10111110000

output:

312889397

result:

ok 1 number(s): "312889397"

Test #13:

score: 0
Accepted
time: 0ms
memory: 35112kb

input:

100 100
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

554554135

result:

ok 1 number(s): "554554135"

Test #14:

score: 0
Accepted
time: 234ms
memory: 35616kb

input:

1000 1000
10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

944188930

result:

ok 1 number(s): "944188930"

Test #15:

score: 0
Accepted
time: 898ms
memory: 35792kb

input:

1999 1999
10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

753324940

result:

ok 1 number(s): "753324940"

Test #16:

score: 0
Accepted
time: 908ms
memory: 35600kb

input:

2000 2000
10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

489943678

result:

ok 1 number(s): "489943678"

Test #17:

score: 0
Accepted
time: 910ms
memory: 35636kb

input:

2000 2000
10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

458543942

result:

ok 1 number(s): "458543942"

Test #18:

score: 0
Accepted
time: 4ms
memory: 35056kb

input:

37 100
0000000000100000010101011000010111111000000000000000000000000000000000001110100110101000000010110000
0111100011011110101011110100101001011000000000110010001010110100000000010000100000111011000000100000
0001110011110000001100011000010011001000000000000000000000000000000000000000000000000000010...

output:

807297668

result:

ok 1 number(s): "807297668"

Test #19:

score: 0
Accepted
time: 6ms
memory: 35268kb

input:

71 93
100010100111111001011100000000011001101101010001011001110001101110010000001000001000000000011
110100111110010001000110000101111010111111000111011010100001010000010110011000000100000000000
110010010110000000010001010100000011000100000010011100100000100100101100010100001100000010000
000101010010...

output:

50935767

result:

ok 1 number(s): "50935767"

Test #20:

score: 0
Accepted
time: 0ms
memory: 35128kb

input:

101 114
010101111101011101100001000100001001000100011100111111110010001111101001100100000110100101010110000000000000001000
101010000011100100000001100000110000111001111011000010010101001011110110100101011101111111111110111010000000000000
11011100100101010100101100000101100000010100000010010110101010...

output:

0

result:

ok 1 number(s): "0"

Test #21:

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

input:

17 2000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010010101111100001010111000001111010110101100011000011011111110001011001011010111110111110000110011101111011010110101011010100110001111110110110101000101110100110011001000010000001010...

output:

526829746

result:

ok 1 number(s): "526829746"

Test #22:

score: 0
Accepted
time: 0ms
memory: 35216kb

input:

30 1999
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

708057099

result:

ok 1 number(s): "708057099"

Test #23:

score: -100
Wrong Answer
time: 10ms
memory: 35512kb

input:

54 2000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

756510740

result:

wrong answer 1st numbers differ - expected: '0', found: '756510740'