QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#287106 | #5442. Referee Without Red | ushg8877 | WA | 793ms | 132508kb | C++14 | 2.6kb | 2023-12-19 16:42:26 | 2023-12-19 16:42:26 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MP make_pair
mt19937 rnd(time(0));
const int MAXN=3e6+5;
const int MOD=998244353;
int n,m;
vector<int> a[MAXN];
ll fac[MAXN],inf[MAXN];
int p[MAXN],q[MAXN],d[MAXN],np,nq;bool visx[MAXN],visy[MAXN];
vector<vector<int> > ls,rs;
ll ksm(ll a,int b){ll r=1;while(b){if(b&1)r=r*a%MOD;a=a*a%MOD,b>>=1;}return r;}
ll repeat(vector<int> a){
int n=a.size();
vector<int> border(n);
border[0]=-1;
for(int i=1;i<n;i++){
int x=border[i-1];
while(x>=0&&a[x+1]!=a[i]) x=border[x];
if(a[x+1]==a[i]) x++;
border[i]=x;
}
if(n%(n-1-border[n-1])) return n;
else return n-1-border[n-1];
}
ll solve_line(int x){
map<int,int> mp;
for(auto &b:rs){
vector<int> p;
for(int i:b) p.push_back(a[x][i]);
ll x=repeat(p);
map<int,int> mx;
while(x>1) mx[d[x]]++,x/=d[x];
for(auto i:mx) mp[i.first]=max(mp[i.first],i.second);
}
ll ans=1;
for(auto i:mp) ans=ans*ksm(i.first,i.second)%MOD;
return ans;
}
ll solve_comm(int x){
map<int,int> mp;
for(auto &b:ls){
vector<int> p;
for(int i:b) p.push_back(a[i][x]);
ll x=repeat(p);
map<int,int> mx;
while(x>1) mx[d[x]]++,x/=d[x];
for(auto i:mx) mp[i.first]=max(mp[i.first],i.second);
}
ll ans=1;
for(auto i:mp) ans=ans*ksm(i.first,i.second)%MOD;
return ans;
}
void solve(){
ls.clear(),rs.clear();
cin>>n>>m;
for(int i=1;i<=n;i++){
a[i].resize(m+1);
for(int j=1;j<=m;j++) cin>>a[i][j];
}
np=nq=0;
for(int i=1;i<=n;i+=2) p[++np]=i;
for(int i=2;i<=n;i+=2) p[++np]=i;
for(int i=1;i<=m;i+=2) q[++nq]=i;
for(int i=2;i<=m;i+=2) q[++nq]=i;
for(int i=1;i<=n;i++) visx[i]=false;
for(int i=1;i<=m;i++) visy[i]=false;
ll ans=1;
for(int i=1;i<=n;i++)
if(p[i]!=i&&!visx[i]){
vector<int> a;
int t=i;
while(!visx[t]) a.push_back(t),visx[t]=true,t=p[t];
ls.push_back(a);
}
for(int i=1;i<=m;i++)
if(q[i]!=i&&!visy[i]){
vector<int> a;
int t=i;
while(!visy[t]) a.push_back(t),visy[t]=true,t=q[t];
rs.push_back(a);
}
for(auto &l:ls) for(auto &r:rs){
map<int,int> mp;
int cnt=0;
for(int i:l) for(int j:r){
cnt++;mp[a[i][j]]++;
}
ans=ans*fac[cnt]%MOD;
for(auto i:mp) ans=ans*inf[i.second]%MOD;
}
for(int i=1;i<=n;i++) if(p[i]==i) ans=ans*solve_line(i)%MOD;
for(int i=1;i<=m;i++) if(q[i]==i) ans=ans*solve_comm(i)%MOD;
cout<<ans<<endl;
return;
}
int main(){
ios::sync_with_stdio(false);
fac[0]=inf[0]=1;
for(int i=1;i<MAXN;i++) inf[i]=ksm(fac[i]=fac[i-1]*i%MOD,MOD-2);
for(int i=2;i<MAXN;i++) for(int j=i;j<MAXN;j+=i)
if(!d[j]) d[j]=i;
int T;cin>>T;
while(T--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 441ms
memory: 132508kb
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: 416ms
memory: 132508kb
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: 793ms
memory: 132484kb
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 194740086 215040 40320 322560 32456681 1166400 887214222 542386470 375765881 9 4 361590980 913481201 527607149 85428015 311271219 16 645120 557106771 388800 173057174 718367389 460990604 1 239327783 9 145293043 40098691 97370043 799392782 155415144 1 36 3991680 645120 545661527 55...
result:
wrong answer 24th numbers differ - expected: '232068778', found: '718367389'