QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#728861 | #4937. Permutation Transformation | trongvan245 | WA | 1ms | 5788kb | C++14 | 2.0kb | 2024-11-09 16:06:12 | 2024-11-09 16:06:17 |
Judging History
answer
// Hello I'm Nekan
//
#include <bits/stdc++.h>
#define Nekan "test"
#define fi first
#define se second
#define pb push_back
#define zs(v) ((int)(v).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define pii pair<int, int>
typedef long double ld;
typedef long long ll;
const int N = 2e5 + 5;
const int LIM = 1e5;
const long long mod = 998244353;
using namespace std;
int n;
int vis[N], p[N], d[N], maxx[N];
int dfs(int u) {
vis[u] = 1;
if (!vis[p[u]])
return dfs(p[u]) + 1;
else
return 1;
}
void xuly() {
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> p[i];
}
int Count = 0, init = 0;
ll ans = 1;
bool flag = true;
for (int i = 1; i <= n; ++i) {
if (vis[i])
continue;
int sz = dfs(i);
// cout << sz << '\n';
while (sz % 2 == 0) {
sz /= 2;
++Count;
}
init = max(Count, init);
if (sz == 1)
continue;
flag = false;
--sz;
while (sz != 1) {
int t = d[sz], Count = 0;
while (sz % t == 0)
sz /= t, ++Count;
maxx[t] = max(maxx[t], Count);
}
}
for (int i = 1; i <= LIM; ++i) {
while (maxx[i]) {
--maxx[i];
ans = ans * i % mod;
// cout << i << '\n';
}
}
if (flag)
ans = 0;
cout << (ans + init) % mod << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
if (fopen(Nekan ".inp", "r")) {
freopen(Nekan ".inp", "r", stdin);
freopen(Nekan ".out", "w", stdout);
}
for (int i = 2; i <= LIM; ++i) {
if (d[i])
continue;
for (int j = i; j <= LIM; j += i)
d[j] = i;
}
int t = 1;
// cin >> t;
while (t--)
xuly();
}
// Surely nothing could go wrong.
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 4060kb
input:
5 3 5 1 2 4
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 1ms
memory: 4064kb
input:
8 7 5 1 6 8 2 3 4
output:
4
result:
ok single line: '4'
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 5788kb
input:
1 1
output:
0
result:
wrong answer 1st lines differ - expected: '1', found: '0'