QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#140590 | #5442. Referee Without Red | xcyle | WA | 179ms | 251912kb | C++20 | 3.7kb | 2023-08-16 11:40:07 | 2023-08-16 11:40:09 |
Judging History
answer
/*
_/ _/ _/_/_/ _/ _/ _/ _/_/_/_/_/
_/ _/ _/ _/ _/ _/ _/ _/
_/ _/ _/ _/ _/ _/ _/
_/_/ _/ _/ _/ _/_/_/_/
_/ _/ _/ _/ _/ _/
_/ _/ _/ _/ _/ _/ _/
_/ _/ _/_/_/ _/ _/_/_/_/_/ _/_/_/_/_/
*/
#include <bits/stdc++.h>
#define ll long long
#define lc(x) ((x) << 1)
#define rc(x) ((x) << 1 | 1)
#define ru(i, l, r) for (int i = (l); i <= (r); i++)
#define rd(i, r, l) for (int i = (r); i >= (l); i--)
#define mid ((l + r) >> 1)
#define pii pair<int, int>
#define mp make_pair
#define fi first
#define se second
#define sz(s) (int)s.size()
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
using namespace std;
#define maxn 3000005
const int mo = 998244353;
mt19937 Rand(chrono::steady_clock::now().time_since_epoch().count());
int read() {
int x = 0, w = 0; char ch = getchar();
while(!isdigit(ch)) w |= ch == '-', ch = getchar();
while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
return w ? -x : x;
}
int n[2], nxt[maxn], vis[maxn], cnt[2], id[2][maxn], tot;
vector<int> s[2][maxn];
vector<int> a[maxn];
void doit(int tp) {
cnt[tp] = 0;
ru(i, 1, n[tp]) s[tp][i].clear(), vis[i] = 0;
int now = 0;
ru(i, 1, n[tp]) if(i & 1) nxt[i] = ++now;
ru(i, 1, n[tp]) if(i % 2 == 0) nxt[i] = ++now;
ru(i, 1, n[tp]) if(!vis[i]) {
cnt[tp]++;
for (int j = i; !vis[j]; j = nxt[j]) s[tp][cnt[tp]].push_back(j), vis[j] = 1;
id[tp][cnt[tp]] = (s[tp][cnt[tp]].size() & 1) ? 1 + tp : ++tot;
}
}
int gcd(int x, int y) {
return !y ? x : gcd(y, x % y);
}
int lcm(int x, int y) {
return (ll)x * y / gcd(x, y);
}
int num, b[maxn], fa[maxn];
int calc() {
int j = 0; nxt[1] = 0;
ru(i, 2, num) {
while(j && b[j + 1] != b[i]) j = nxt[j];
if(b[j + 1] == b[i]) j++;
nxt[i] = j;
}
return nxt[num] * 2 >= num ? num - nxt[num] : num;
}
int buc[maxn], inv[maxn], fac[maxn];
int find(int x) {
return x == fa[x] ? x : fa[x] = find(fa[x]);
}
void solve() {
ru(i, 0, 1) n[i] = read(); tot = 2;
ru(i, 1, n[0]) {
a[i] = {0};
ru(j, 1, n[1]) a[i].push_back(read());
}
doit(0), doit(1);
ru(i, 1, tot) fa[i] = i;
int ans = 1;
ru(i, 0, 1) {
ru(j, 1, cnt[i]) if(s[i][j].size() == 1) {
int res = 1;
ru(k, 1, cnt[i ^ 1]) {
num = 0;
for (auto x: s[i ^ 1][k]) b[++num] = i ? a[x][s[i][j][0]] : a[s[i][j][0]][x];
res = lcm(res, calc());
}
ans = (ll)ans * res % mo;
}
}
ru(i, 1, cnt[0]) ru(j, 1, cnt[1]) if(s[0][i].size() > 1 && s[1][j].size() > 1) {
int tmp = 1;
for (auto x: s[0][i]) for (auto y: s[1][j]) {
buc[a[x][y]]++;
tmp = (ll)tmp * inv[buc[a[x][y]]] % mo;
}
for (auto x: s[0][i]) for (auto y: s[1][j]) buc[a[x][y]]--;
ans = (ll)ans * fac[s[0][i].size() * s[1][j].size()] % mo * tmp % mo;
if(tmp == 1) {
int x = find(id[0][i]), y = find(id[1][j]);
if(x ^ y) fa[x] = y;
else ans = (ll)ans * inv[2] % mo;
}
}
printf("%d\n", ans);
}
int main() {
inv[1] = 1; ru(i, 2, maxn - 1) inv[i] = (ll)(mo - mo / i) * inv[mo % i] % mo;
fac[0] = 1; ru(i, 1, maxn - 1) fac[i] = (ll)fac[i - 1] * i % mo;
int T = read();
while(T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 47ms
memory: 241468kb
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: 53ms
memory: 240120kb
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: 179ms
memory: 251912kb
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 464137556 460990604 1 618786068 9 571768698 40098691 97370043 799392782 155415144 1 36 3991680 645120 545661527 55...
result:
wrong answer 24th numbers differ - expected: '232068778', found: '464137556'