QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#103251 | #6344. The Best Problem of 2021 | Crysfly | WA | 2ms | 34712kb | C++11 | 4.4kb | 2023-05-04 21:10:15 | 2023-05-04 21:10:19 |
Judging History
answer
#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)
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,int b){return a.x==b;}
friend bool operator !=(modint a,int b){return a.x!=b;}
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 2005
#define inf 0x3f3f3f3f
typedef bitset<maxn>bint;
int m,n;
string str;
bint X;
bint bs[maxn];
void ins(bint x){
Rep(i,n-1,0)
if(x[i]){
if(!bs[i][i])return bs[i]=x,void();
x^=bs[i];
}
puts("0"),exit(0);
}
void gauss(){
Rep(i,n-1,0)
For(j,0,i-1)
if(bs[j][i])bs[j]^=bs[i];
}
bool operator <=(bint a,bint b){
Rep(i,2000,0)
if(a[i]!=b[i])return a[i]<b[i];
return 1;
}
void workX(){
bint now,mx;
now.reset();
cin>>str,reverse(str.begin(),str.end());
For(i,0,n-1)mx[i]=str[i]&1;
m=0;
Rep(i,n-1,0){
if(!bs[i][i])continue;
now^=bs[i];
if(now<=mx)X[m]=1;
else X[m]=0,now^=bs[i];
++m;
}
if(!X[0])puts("0"),exit(0);
n=m;
}
modint f[2005][2005],g[2005][2005];
modint q,pw[maxn],qfac[maxn],qifac[maxn];
void initq(int n){
pw[0]=qfac[0]=qifac[0]=1;
For(i,1,n)pw[i]=pw[i-1]*q,qfac[i]=qfac[i-1]*(pw[i]-1),qifac[i]=qifac[i-1]/(pw[i]-1);
}
inline modint qc(int n,int m){
if(m<0||n<m)return 0;
return qfac[n]*qifac[m]*qifac[n-m];
}
modint pwpw[2005]; // qpow(2,qpow(2,i))
modint ans[2005];
signed main()
{
m=read(),n=read();
For(_,1,m){
cin>>str,reverse(str.begin(),str.end());
bint x; x.reset();
For(i,0,n-1) x[i]=str[i]&1;
ins(x);
}
gauss();
workX();
q=2,initq(2001);
pwpw[0]=2;
For(i,1,n)pwpw[i]=pwpw[i-1]*pwpw[i-1];
// 钦定 n 有
modint iv2=(mod+1)/2;
f[0][0]=1; // has't hit lcp
g[0][0]=2; // has hit lcp
For(i,0,n-1)cout<<X[n-1-i];puts(" x");
For(i,0,n-1)
For(j,0,i){
if(X[n-1-i]){
// add one:
if(i==n-1){
g[i+1][j+1]+=g[i][j]*pw[i]*pwpw[j];
continue;
}
f[i+1][j+1]+=f[i][j]*pw[i];
g[i+1][j+1]+=g[i][j]*pw[i]*(1+pwpw[j])*iv2;
// not add one:
// 1/2 same , 1/2 diff
// same:
f[i+1][j]+=f[i][j]*iv2;
g[i+1][j]+=g[i][j]*iv2;
// diff:
f[i+1][j]+=f[i][j]*iv2;
g[i+1][j]+=f[i][j]*iv2*pwpw[j];
}else{
// add one:
f[i+1][j+1]+=f[i][j]*pw[i];
g[i+1][j+1]+=g[i][j]*pw[i]*(1+pwpw[j])*iv2;
// same:
f[i+1][j]+=f[i][j]*iv2;
g[i+1][j]+=g[i][j]*iv2;
// diff:
f[i+1][j]+=f[i][j]*iv2;
g[i+1][j]+=f[i][j]*iv2;
}
}
For(i,1,n) cout<<g[n][i].x<<" \n"[i==n];
ans[0]=2;
For(i,1,n) ans[i]=g[n][i]+pwpw[i]*qc(n-1,i);
For(i,0,n) cout<<ans[i].x<<" ";puts("");
modint res=0;
For(i,0,n) res+=ans[i]*sign(n-i)*qpow(2,1ll*(n-i)*(n-i-1)/2%(mod-1));
res*=iv2;
cout<<res.x;
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 34712kb
input:
4 4 0001 0010 0100 1000 1101
output:
1011 x 28 608 13248 1044480 2 56 720 13504 1044480 516048
result:
wrong answer 1st numbers differ - expected: '7364', found: '1011'