QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#99968 | #6344. The Best Problem of 2021 | tricyzhkx | WA | 2ms | 3740kb | C++14 | 2.3kb | 2023-04-24 11:08:55 | 2023-04-24 11:08:59 |
Judging History
answer
# include <bits/stdc++.h>
using namespace std;
const int mod=998244353,_2=(mod+1)/2;
typedef long long ll;
typedef bitset<2001> Num;
int n,m,pos[2010],X[2010],pw[2010],pwpw[2010],ans[2010],f[2010][2010],g[2010][2010],h[2010][2010];
ll qfac[2010],qinv[2010];
char s[2010];
Num d[2010],a;
template<typename T>
void upd(int &a,T b){a=(a+b)%mod;}
ll qC(int n,int m){return n<m || m<0?0:qfac[n]*qinv[n-m]%mod*qinv[m]%mod;}
ll power(ll a,int b)
{
ll ans=1;
for(;b;b>>=1,a=a*a%mod)
if(b&1) ans=ans*a%mod;
return ans;
}
bool operator<=(const Num &a,const Num &b)
{
for(int i=m-1;i>=0;i--)
if(a[i]!=b[i]) return a[i]<b[i];
return true;
}
bool insert(Num a)
{
for(int i=m-1;i>=0;i--)
if(a[i])
{
if(d[i].any()) a^=d[i];
else
{
d[i]=a;
return true;
}
}
return false;
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
scanf("%s",s);
for(int j=0;j<m;j++) a[m-j-1]=s[j]-'0';
if(!insert(a)) return puts("0"),0;
}
for(int i=0;i<m;i++)if(d[i].any())
for(int j=i+1;j<m;j++)
if(d[j][i]) d[j]^=d[i];
for(int i=0,j=0;i<m;i++)
if(d[i].any()) pos[j++]=i;
Num cur,lim;
scanf("%s",s);
for(int i=0;i<m;i++) lim[m-i-1]=s[i]-'0';
for(int i=n-1;i>=0;i--)
if((cur^d[pos[i]])<=lim) cur^=d[pos[i]],X[i]=1;
if(!X[n-1]) return puts("0"),0;
qfac[0]=qinv[0]=pw[0]=1;pwpw[0]=2;
for(int i=1;i<=n;i++) pw[i]=pw[i-1]*2%mod,pwpw[i]=(ll)pwpw[i-1]*pwpw[i-1]%mod;
for(int i=1;i<=n;i++) qfac[i]=qfac[i-1]*(pw[i]-1)%mod;
qinv[n]=power(qfac[n],mod-2);
for(int i=n;i>=1;i--) qinv[i-1]=qinv[i]*(pw[i]-1)%mod;
f[0][0]=g[0][1]=h[0][1]=2;
for(int i=1;i<=n;i++)
for(int j=1;j<=i;j++)
if(X[i-1])
{
upd(f[i][j],g[i-1][j]*pwpw[j-1]);
upd(g[i][j],qC(i-1,j-1)*pw[i-j]%mod*pwpw[j-1]);
upd(g[i][j],g[i-1][j]);
upd(h[i][j],2*qC(i-1,j-1)*pw[i-j]%mod*pwpw[j-1]);
upd(g[i][j+1],f[i][j]*pw[i-j]);
upd(h[i][j+1],f[i][j]*pw[i-j]);
}
else
{
upd(f[i][j],h[i-1][j]);
upd(g[i][j],g[i-1][j]);
upd(g[i][j],qC(i-1,j-1)*pw[i-j]);
upd(h[i][j],2ll*h[i-1][j]);
upd(g[i][j+1],f[i][j]*pw[i-j]);
upd(h[i][j+1],f[i][j]*pw[i-j]);
}
for(int i=1;i<=n;i++) ans[i]=(f[n][i]+qC(n-1,i)*pwpw[i])%mod;
ans[0]=2;
for(int i=1;i<=n;i++)
for(int j=0;j<i;j++)
ans[i]=(ans[i]+(mod-qC(n-j,i-j))*ans[j])%mod;
cout<<(ll)ans[n]*_2%mod<<endl;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3528kb
input:
4 4 0001 0010 0100 1000 1101
output:
7364
result:
ok 1 number(s): "7364"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3460kb
input:
3 2 00 00 00 11
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 2ms
memory: 3724kb
input:
2 3 110 101 101
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 2ms
memory: 3740kb
input:
3 10 1111100110 0011110100 0101100001 1110000001
output:
38
result:
ok 1 number(s): "38"
Test #5:
score: -100
Wrong Answer
time: 2ms
memory: 3576kb
input:
7 13 1000101001000 1000000010000 1010101011111 1001100100111 1111111101100 0101010101110 1101100010100 1000010011001
output:
53998981
result:
wrong answer 1st numbers differ - expected: '744450298', found: '53998981'