QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#74406 | #5442. Referee Without Red | vme50 | WA | 165ms | 83636kb | C++14 | 2.7kb | 2023-02-01 08:15:04 | 2023-02-01 08:15:06 |
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++)
char buf[LIM],*P1=buf,*P2=buf;
int T,n1,n2,m1,m2,tp1,tp2,w,ans,z[N],nxt[N],fa[N*2],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;
}
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 f(int x1,int x2) {return a[x1*n2+x2];}
int findRt(int u) {return u==fa[u]?u:fa[u]=findRt(fa[u]);}
bool merge(int u,int v)
{u=findRt(u);v=findRt(v);if(u==v) return 0;fa[u]=v;return 1;}
int gcd(int x,int y) {return y?gcd(y,x%y):x;}
int lcm(int x,int y) {return x/gcd(x,y)*y;}
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);}w=1;
for(int i=1;i<=tp2;++i)
{z[0]=0;for(auto j:vc2[i]) z[++z[0]]=f(0,j);w=lcm(w,slv1());}
ans=1ll*ans*w%MOD;w=1;
for(int i=1;i<=tp1;++i)
{z[0]=0;for(auto j:vc1[i]) z[++z[0]]=f(j,0);w=lcm(w,slv1());}
ans=1ll*ans*w%MOD;w=1;
if(!(n1&1)) for(int i=1;i<=tp2;++i)
{z[0]=0;for(auto j:vc2[i]) z[++z[0]]=f(m1,j);w=lcm(w,slv1());}
ans=1ll*ans*w%MOD;w=1;
if(!(n2&1)) for(int i=1;i<=tp1;++i)
{z[0]=0;for(auto j:vc1[i]) z[++z[0]]=f(j,m2);w=lcm(w,slv1());}
ans=1ll*ans*w%MOD;for(int i=0;i<=tp1+tp2;++i) fa[i]=i;
for(int i1=1,t,u,v,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(!fl)
{
u=vc1[i1].size()&1?0:tp1+i2;v=vc2[i2].size()&1?0:i1;
if(!merge(u,v)) ans=1ll*ans*inv[2]%MOD;printf("i=%d %d\n",i1,i2);
}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: 46ms
memory: 62116kb
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: 0
Accepted
time: 35ms
memory: 62156kb
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:
690561281
result:
ok 1 number(s): "690561281"
Test #3:
score: -100
Wrong Answer
time: 165ms
memory: 83636kb
input:
71117 7 8 2868391 1228870 2892937 349733 664891 1675356 1981526 762573 2892937 2892937 664891 1228870 959280 762573 664891 959280 349733 250147 1675356 349733 349733 762573 1675356 250147 1675356 959280 664891 250147 250147 250147 2868391 959280 1675356 664891 250147 1228870 1981526 250147 2868391 2...
output:
462363428 38853786 i=1 1 194740086 215040 40320 322560 i=2 1 32456681 1166400 887214222 i=2 1 542386470 375765881 9 4 i=2 1 361590980 913481201 527607149 85428015 311271219 16 645120 557106771 388800 i=1 2 173057174 i=1 1 i=1 2 i=2 1 i=2 2 232068778 460990604 1 i=1 2 i=2 2 239327783 9 i=2 1 i=2 2 14...
result:
wrong output format Expected integer, but "i=1" found