QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#74366 | #5442. Referee Without Red | vme50 | WA | 34ms | 73244kb | C++14 | 2.2kb | 2023-01-31 21:38:53 | 2023-01-31 21:38:54 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define N 1000005
#define M 3000005
#define LIM 10000005
#define MOD 998244353
#define pb push_back
//#define gc() (P1==P2 && (P2=(P1=buf)+fread(buf,1,LIM,stdin),P1==P2)?EOF:*P1++)
#define gc getchar
char buf[LIM],*P1=buf,*P2=buf;
int T,n1,n2,m1,m2,tp1,tp2,ans,z[N],nxt[N],a[M],inv[M],nw[M];
bool vs1[N],vs2[N];vector<int> vc1[N],vc2[N];
int rd()
{
int res=0;char c=0;while(!isdigit(c)) c=gc();
while(isdigit(c)) res=res*10+(c-48),c=gc();return res;
}
int f(int x1,int x2) {return a[x1*n2+x2];}
void init(int n)
{for(int i=1;i<=n;++i) inv[i]=i>1?1ll*inv[MOD%i]*(MOD-MOD/i)%MOD:1;}
int slv1()
{
for(int i=2,t=0;i<=z[0];++i)
{while(t && z[i]!=z[t+1]) t=nxt[t];if(z[i]==z[t+1]) ++t;nxt[i]=t;}
for(int i=nxt[z[0]];i;i=nxt[i])
if(!(z[0]%(z[0]-i))) return z[0]-i;return z[0];
}
void slv()
{
n1=rd();n2=rd();for(int i=0;i<n1*n2;++i) a[i]=rd();
m1=n1-(!(n1&1));m2=n2-(!(n2&1));ans=1;
for(int i=1;i<=tp1;++i) vc1[i].clear();
for(int i=1;i<=tp2;++i) vc2[i].clear();tp1=tp2=0;
for(int i=0;i<n1;++i) vs1[i]=0;for(int i=0;i<n2;++i) vs2[i]=0;
for(int i=1;i<m1;++i) if(!vs1[i])
{++tp1;for(int j=i;!vs1[j];j=(j*2)%m1) vs1[j]=1,vc1[tp1].pb(j);}
for(int i=1;i<m2;++i) if(!vs2[i])
{++tp2;for(int j=i;!vs2[j];j=(j*2)%m2) vs2[j]=1,vc2[tp2].pb(j);}
for(int i=1;i<=tp1;++i)
{z[0]=0;for(auto j:vc1[i]) z[++z[0]]=f(j,0);ans=1ll*ans*slv1()%MOD;}
for(int i=1;i<=tp2;++i)
{z[0]=0;for(auto j:vc2[i]) z[++z[0]]=f(0,j);ans=1ll*ans*slv1()%MOD;}
if(!(n2&1)) for(int i=1;i<=tp1;++i)
{z[0]=0;for(auto j:vc1[i]) z[++z[0]]=f(j,m2);ans=1ll*ans*slv1()%MOD;}
if(!(n1&1)) for(int i=1;i<=tp2;++i)
{z[0]=0;for(auto j:vc2[i]) z[++z[0]]=f(m1,j);ans=1ll*ans*slv1()%MOD;}
for(int i1=1,t,nw1;i1<=tp1;++i1) for(int i2=1;i2<=tp2;++i2)
{
bool fl=0;nw1=0;
for(auto j1:vc1[i1]) for(auto j2:vc2[i2])
{
t=f(j1,j2);++nw1;++nw[t];fl|=(nw[t]>1);
ans=1ll*ans*nw1%MOD*inv[nw[t]]%MOD;
}if(nw1>1 && nw1&1 && !fl) ans=1ll*ans*inv[2]%MOD;
for(auto j1:vc1[i1]) for(auto j2:vc2[i2]) --nw[f(j1,j2)];
}printf("%d\n",ans);
}
int main() {init(3e6);T=rd();while(T--) slv();return 0;}
詳細信息
Test #1:
score: 100
Accepted
time: 21ms
memory: 72336kb
input:
2 4 4 1 2 3 4 3 4 1 2 1 2 4 1 4 3 3 2 3 9 1 8 1 1 8 1 1 8 1 1 8 8 8 8 8 8 8 1 1 1 1 8 8 8 1 1 1
output:
96 6336
result:
ok 2 number(s): "96 6336"
Test #2:
score: -100
Wrong Answer
time: 34ms
memory: 73244kb
input:
1 18 16 8 8 1 1 8 8 8 1 8 8 8 1 8 8 8 1 8 1 8 1 8 1 1 1 8 1 1 1 8 1 1 1 8 8 8 1 8 8 8 1 8 8 8 1 8 8 8 1 8 8 1 1 8 1 1 1 8 1 1 1 8 1 1 1 8 1 8 1 8 8 8 1 8 1 1 1 8 8 8 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 8 8 1 1 8 8 8 1 8 8 8 1 7 7 7 1 8 1 8 1 8 1 1 1 8 1 1 1 1 1 7 1 8 8 8 1 8 8 8 1 8 8 8 1 1 7 7 1 8 8 ...
output:
546340904
result:
wrong answer 1st numbers differ - expected: '690561281', found: '546340904'