QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#649002 | #5442. Referee Without Red | zwh2008 | WA | 71ms | 194024kb | C++14 | 3.0kb | 2024-10-17 21:15:15 | 2024-10-17 21:15:15 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using pi=pair<int,int>;
#define fi first
#define se second
const int N=3e6+5,mod=998244353,i2=(mod+1)/2;
int n,m,n0,m0,p[N],q[N],nxt[N],ct[N],fa[N*2],mlt[N];
bool vis[N],isp[N];
ll inv[N],fc[N];
vector<vector<int>>a;
vector<int>cx[N],cy[N];
ll qp(ll a,int b){ll ans=1;for(;b;b>>=1,a=a*a%mod)if(b&1)ans=ans*a%mod;return ans;}
int gf(int x){return x==fa[x]?x:fa[x]=gf(fa[x]);}
ll lcm(ll x,ll y){return x/__gcd(x,y)*y;}
void init(int n) {
fc[0]=1;for(int i=1;i<=n;i++)fc[i]=fc[i-1]*i%mod;
inv[n]=qp(fc[n],mod-2),fill(isp+2,isp+n+1,1);
for(int i=n-1;~i;i--)inv[i]=inv[i+1]*(i+1)%mod;
for(int i=2;i*i<=n;i++)if(isp[i])for(int j=i*i;j<=n;j+=i)isp[j]=0;
}
int calc(vector<int>&a) {
int n=a.size();nxt[1]=0;
for(int i=2;i<=n;i++) {
int j=nxt[i-1];
while(j&&a[j]!=a[i-1])j=nxt[j];
nxt[i]=j+(a[i-1]==a[j]);
}return n%(n-nxt[n])?n:n-nxt[n];
}
void ad(int x) {
for(int i=1;i<=x;i++)if(isp[i]) {
int mul=1;while(x/mul%i==0)mul*=i;
mlt[i]=max(mlt[i],mul);
}
}
void solve() {
cin>>n>>m,n0=m0=0;
a=vector<vector<int>>(n+1,vector<int>(m+1));
for(int i=1;i<=n;i++)p[i]=(i&1?i/2+1:(n+1)/2+i/2);
for(int i=1;i<=m;i++)q[i]=(i&1?i/2+1:(m+1)/2+i/2);
for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)cin>>a[i][j];
fill(vis,vis+n+1,0);
for(int i=1;i<=n;i++)if(!vis[i]) {
int x=i;cx[++n0].clear();
while(!vis[x])cx[n0].push_back(x),vis[x]=1,x=p[x];
}
fill(vis,vis+m+1,0);
for(int i=1;i<=m;i++)if(!vis[i]) {
int x=i;cy[++m0].clear();
while(!vis[x])cy[m0].push_back(x),vis[x]=1,x=q[x];
}
ll ans=1;
for(int i=1;i<=n;i++)if(p[i]==i) {
ll s=1;fill(mlt+1,mlt+m+1,1);
for(int j=1;j<=m0;j++) {
vector<int>v;
for(int k:cy[j])v.push_back(a[i][k]);
ad(calc(v));
}
for(int j=1;j<=m;j++)ans=ans*mlt[j]%mod;
}
for(int i=1;i<=m;i++)if(q[i]==i) {
ll s=1;fill(mlt+1,mlt+m+1,1);
for(int j=1;j<=n0;j++) {
vector<int>v;
for(int k:cx[j])v.push_back(a[k][i]);
ad(calc(v));
}
for(int j=1;j<=n;j++)ans=ans*mlt[j]%mod;
}
iota(fa+1,fa+n0+m0+2,1);
for(int i=1;i<=n0;i++)if(cx[i].size()!=1)for(int j=1;j<=m0;j++)if(cy[j].size()!=1) {
bool fl=0;int p=cx[i].size(),q=cy[j].size();
for(int x:cx[i])for(int y:cy[j])fl|=ct[a[x][y]],ct[a[x][y]]++;
ans=ans*fc[p*q]%mod;
for(int x:cx[i])for(int y:cy[j])ans=ans*inv[ct[a[x][y]]]%mod,ct[a[x][y]]=0;
if(!fl) {
int x=(cy[j].size()&1?n0+m0+1:i),y=(cx[i].size()&1?n0+m0+1:n0+j);
x=gf(x),y=gf(y);if(x!=y)fa[x]=y;else ans=ans*i2%mod;
}
}cout<<ans<<'\n';
}
int main() {
#ifndef ONLINE_JUDGE
freopen(".in","r",stdin);
freopen(".out","w",stdout);
#endif
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int tt;cin>>tt,init(3e6);
while(tt--)solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 63ms
memory: 194024kb
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: 71ms
memory: 194012kb
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:
0
result:
wrong answer 1st numbers differ - expected: '690561281', found: '0'