QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#99610 | #6344. The Best Problem of 2021 | xiaoyaowudi | WA | 134ms | 63936kb | C++17 | 4.4kb | 2023-04-23 08:23:49 | 2023-04-23 08:23:53 |
Judging History
answer
#include <iostream>
#include <algorithm>
#include <bitset>
constexpr int N(2010),p(998244353);
std::bitset<N> b[N];bool hv[N];
int fp(int a,int b){int ans(1),off(a);while(b){if(b&1) ans=1ll*ans*off%p;off=1ll*off*off%p;b>>=1;}return ans;}
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n,m;
std::cin>>n>>m;
static std::bitset<N> a[N],xb;
for(int i(1);i<=n;++i)
{
static char s[N];std::cin>>s;
for(int j(0);j<m;++j)
{
a[i][m-j-1]=(s[j]=='1');
}
bool st(false);
for(int j(m-1);j>=0;--j) if(a[i][j])
{
if(hv[j])
{
a[i]^=b[j];
}
else
{
hv[j]=st=true;
b[j]=a[i];
break;
}
}
if(!st){std::cout<<0<<std::endl;return 0;}
}
{
static char s[N];std::cin>>s;
for(int j(0);j<m;++j) xb[m-j-1]=(s[j]=='1');
}
for(int i(m-1);i>=0;--i) if(hv[i]) for(int j(i+1);j<m;++j) if(hv[j] && b[j][i]) b[j]^=b[i];
static int x[N];int cnt(0);
static std::bitset<N> cur;
for(int j(m-1);j>=0;--j) if(hv[j])
{
std::bitset<N> nw(cur^b[j]);
bool cap(true);
for(int t(m-1);t>=0;--t) if(xb[t]!=nw[t])
{
if(xb[t]<nw[t]) cap=false;
break;
}
if(cap) cur=nw,x[++cnt]=1;
else x[++cnt]=0;
}
if(!x[1]){std::cout<<0<<std::endl;}
// {
// ++x[cnt];int t(cnt);
// while(x[t]==2) x[t]=0,x[--t]+=1;
// }
// for(int i(1);i<=cnt;++i) std::cout<<x[i]<<" ";std::cout<<std::endl;
static int p2[N],pp2[N],ip2[N],ipr[N][N],inv[N];p2[0]=1;pp2[0]=2;ip2[0]=1;
constexpr int inv2((p+1)/2);
static int f[N][N],g[N][N]/*,h[N][N]*/;
for(int i(1);i<N;++i) p2[i]=2ll*p2[i-1]%p,pp2[i]=1ll*pp2[i-1]*pp2[i-1]%p,ip2[i]=1ll*ip2[i-1]*inv2%p;
inv[1]=1;for(int i(2);i<N;++i) inv[i]=1ll*(p-p/i)*inv[p%i]%p;
for(int i(0);i<N;++i){ipr[i][0]=1;for(int j(1);j<N;++j) ipr[i][j]=1ll*ipr[i][j-1]*ip2[i]%p;}
static int pre[N][N],qf[N],iqf[N],jc[N];
qf[0]=iqf[0]=1;for(int i(1);i<N;++i) qf[i]=1ll*qf[i-1]*(p2[i]-1)%p,iqf[i]=fp(qf[i],p-2);
auto qb=[](int a,int b)->int{return 1ll*qf[a]*iqf[b]%p*iqf[a-b]%p;};
jc[0]=1;
// h[0][0]=1;
// for(int i(1);i<=cnt;++i)
// {
// for(int j(1);)
// }
for(int i(1);i<=cnt;++i)
{
jc[i]=1;
for(int j(1);j<=i;++j) jc[i]=1ll*jc[i]*p2[j-1]%p;
// std::cerr<<jc[i]<<" ";
}
// std::cerr<<std::endl;
for(int i(0);i<N;++i) for(int j(0);j<=i;++j) pre[i][j]=1ll*qb(i,j)*jc[j]%p;
// for(int i(0);i<=cnt;++i) for(int j(0);j<=cnt;++j) std::cout<<pre[i][j]<<" \n"[j==cnt];
// if(!x[0])
// {
f[cnt][0]=2;
for(int i(cnt);i;--i)
{
int c(x[i]);
for(int j(0);j<=cnt-i;++j)
{
// std::cerr<<i<<" "<<j<<" "<<f[i][j]<<std::endl;
if(i<cnt && x[i+1]==1)
{
f[i][j]=(f[i][j]+1ll*ipr[cnt-i][j]*inv2%p*pp2[j]%p*pre[cnt-i-1][j])%p;
}
if(i<cnt && x[i+1]==0)
{
g[i][j]=(g[i][j]+1ll*ipr[cnt-i][j]*inv2%p*pre[cnt-i-1][j])%p;
}
// std::cerr<<i<<" "<<j<<" "<<g[i][j]<<std::endl;
if(i==1) continue;
g[i-1][j]=(g[i-1][j]+1ll*g[i][j]*ip2[j+1])%p;
if(!c)
{
f[i-1][j+1]=(f[i-1][j+1]+1ll*ip2[j+1]*f[i][j])%p;
f[i-1][j]=(f[i-1][j]+1ll*ip2[j+1]*f[i][j])%p;
g[i-1][j+1]=(g[i-1][j+1]+1ll*g[i][j]*ip2[j+1])%p;
}
else
{
f[i-1][j]=(f[i-1][j]+1ll*ip2[j+1]*f[i][j])%p;
f[i-1][j+1]=(f[i-1][j+1]+1ll*pp2[j]*ip2[j+1]%p*f[i][j])%p;
f[i-1][j+1]=(f[i-1][j+1]+1ll*pp2[j]*ip2[j+2]%p*g[i][j])%p;
g[i-1][j+1]=(g[i-1][j+1]+1ll*g[i][j]*ip2[j+2]%p*pp2[j])%p;
}
}
}
static int sum[N];
sum[0]=1;
for(int j(1);j<=cnt;++j)
{
sum[j]=(1ll*pp2[j]*pre[cnt-1][j]+1ll*pp2[j-1]*f[1][j-1]%p*fp(2,(cnt-1)*j)+1ll*pp2[j-1]*g[1][j-1]%p*fp(2,(cnt-1)*j))%p;
// std::cerr<<(1ll*pp2[j-1]*f[1][j-1]%p*fp(2,(cnt-1)*j)+1ll*pp2[j-1]*g[1][j-1]%p*fp(2,(cnt-1)*j))%p<<std::endl;
// std::cerr<<1ll*pp2[j-1]*f[1][j-1]%p*fp(2,(cnt-1)*j)<<std::endl;
// std::cout<<sum[j]<<std::endl;
}
// std::cout<<std::endl;
for(int j(1);j<=cnt;++j) sum[j]=1ll*sum[j]*fp(jc[j],p-2)%p*inv2%p/*,std::cout<<sum[j]<<" "*/;
// std::cout<<std::endl;
int ans(0);
for(int j(0);j<=cnt;++j)
{
for(int k(0);k<j;++k)
{
sum[j]=(sum[j]+1ll*(p-sum[k])*qb(cnt-k,j-k))%p;
}
// std::cerr<<sum[j]<<" ";
}
// std::cerr<<std::endl;
std::cout<<sum[cnt]<<std::endl;
// }
// else
// {
// int ans(0);
// for(int j(0);j<=cnt;++j)
// {
// if((cnt-j)&1) ans=(ans+1ll*(p-pp2[j])*qb(cnt,j))%p;
// else ans=(ans+1ll*pp2[j]*qb(cnt,j))%p;
// }
// std::cout<<ans<<std::endl;
// }
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 25ms
memory: 39772kb
input:
4 4 0001 0010 0100 1000 1101
output:
7364
result:
ok 1 number(s): "7364"
Test #2:
score: 0
Accepted
time: 2ms
memory: 3344kb
input:
3 2 00 00 00 11
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 26ms
memory: 39736kb
input:
2 3 110 101 101
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 24ms
memory: 38380kb
input:
3 10 1111100110 0011110100 0101100001 1110000001
output:
38
result:
ok 1 number(s): "38"
Test #5:
score: 0
Accepted
time: 20ms
memory: 39508kb
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: 20ms
memory: 39744kb
input:
100 100 1111010111010001011111110010101001001101000000000000011000001100101000100011100011000000110000001010 1001001110111010100100010111100010111110101100101000010111001011111010111100111000000011101010100111 000011010111000100110100010010011101001111100110111000100101010001101100101011000111101101...
output:
19562313
result:
ok 1 number(s): "19562313"
Test #7:
score: 0
Accepted
time: 39ms
memory: 42180kb
input:
400 500 1011011011010010111110101001010011000100001111000111111111001111100010101011110011010010011100100100111111000111001110111100101010000000100100011011011001011100100000000100001100001010100010111000110011000100101001010110110100110101000011011011011100111110010100101000011001100000001100001000...
output:
681985268
result:
ok 1 number(s): "681985268"
Test #8:
score: 0
Accepted
time: 57ms
memory: 51040kb
input:
999 1997 011101110101100100111101100000000100001110010001010100011010111010101101011100001000010001110100110111101101010111010011101111011001011100110110101011111011000111101011011000010101100101001110000111010101111100000100100101110000111001010101110110000001111111100110110011110100101000011100011...
output:
435150194
result:
ok 1 number(s): "435150194"
Test #9:
score: 0
Accepted
time: 115ms
memory: 63584kb
input:
1901 2000 10000111000111010000000000100110001100110010011001101110001011000001011000010111101110111001111000010110110100010100010101011111011101100111010101010001010010111010001011000001011010100011000101101010001110111100000101110110011001101111101111000100001010011101011110001100110001100000111110...
output:
9254020
result:
ok 1 number(s): "9254020"
Test #10:
score: 0
Accepted
time: 134ms
memory: 63776kb
input:
1984 2000 11111101001011101001011011010011000001100000101000001001111000100010011011000110110110100000001100000000001111101001111010111110000000010000000111111001010111101101110000111110010111001011011111010010110001011100110101000110000100010100100101010111101100000011110010010100101011101001110110...
output:
870006511
result:
ok 1 number(s): "870006511"
Test #11:
score: 0
Accepted
time: 36ms
memory: 4504kb
input:
2000 2000 00010001100000101100000110010101010101110010001000000100010010110010001100110000001110100111010110100110101010101111011100001110100011001000010001000011100111010100110101000111010010010111001001101100100000101001111111001111101001000101001011101001010010010101011110111001101101101001001000...
output:
0
result:
ok 1 number(s): "0"
Test #12:
score: 0
Accepted
time: 35ms
memory: 39488kb
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: 31ms
memory: 38272kb
input:
100 100 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
554554135
result:
ok 1 number(s): "554554135"
Test #14:
score: 0
Accepted
time: 50ms
memory: 49988kb
input:
1000 1000 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
944188930
result:
ok 1 number(s): "944188930"
Test #15:
score: 0
Accepted
time: 103ms
memory: 63924kb
input:
1999 1999 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
753324940
result:
ok 1 number(s): "753324940"
Test #16:
score: 0
Accepted
time: 88ms
memory: 63860kb
input:
2000 2000 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
489943678
result:
ok 1 number(s): "489943678"
Test #17:
score: 0
Accepted
time: 99ms
memory: 63936kb
input:
2000 2000 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
458543942
result:
ok 1 number(s): "458543942"
Test #18:
score: 0
Accepted
time: 14ms
memory: 39576kb
input:
37 100 0000000000100000010101011000010111111000000000000000000000000000000000001110100110101000000010110000 0111100011011110101011110100101001011000000000110010001010110100000000010000100000111011000000100000 0001110011110000001100011000010011001000000000000000000000000000000000000000000000000000010...
output:
807297668
result:
ok 1 number(s): "807297668"
Test #19:
score: 0
Accepted
time: 28ms
memory: 39776kb
input:
71 93 100010100111111001011100000000011001101101010001011001110001101110010000001000001000000000011 110100111110010001000110000101111010111111000111011010100001010000010110011000000100000000000 110010010110000000010001010100000011000100000010011100100000100100101100010100001100000010000 000101010010...
output:
50935767
result:
ok 1 number(s): "50935767"
Test #20:
score: 0
Accepted
time: 2ms
memory: 5420kb
input:
101 114 010101111101011101100001000100001001000100011100111111110010001111101001100100000110100101010110000000000000001000 101010000011100100000001100000110000111001111011000010010101001011110110100101011101111111111110111010000000000000 11011100100101010100101100000101100000010100000010010110101010...
output:
0
result:
ok 1 number(s): "0"
Test #21:
score: 0
Accepted
time: 27ms
memory: 39560kb
input:
17 2000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010010101111100001010111000001111010110101100011000011011111110001011001011010111110111110000110011101111011010110101011010100110001111110110110101000101110100110011001000010000001010...
output:
526829746
result:
ok 1 number(s): "526829746"
Test #22:
score: 0
Accepted
time: 31ms
memory: 39784kb
input:
30 1999 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
708057099
result:
ok 1 number(s): "708057099"
Test #23:
score: -100
Wrong Answer
time: 28ms
memory: 38468kb
input:
54 2000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
0 508205194
result:
wrong answer Output contains longer sequence [length = 2], but answer contains 1 elements