QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#243522 | #4937. Permutation Transformation | ideograph_advantage# | WA | 0ms | 3748kb | C++14 | 1.9kb | 2023-11-08 13:37:34 | 2023-11-08 13:37:35 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define iter(v) v.begin(), v.end()
#define SZ(v) (int)v.size()
#define pb emplace_back
#define ff first
#define ss second
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U>
void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r){
while(l != r) cout << *l << " ", l++;
cout << endl;
}
#else
#define debug(...) void()
#define pary(...) void()
#endif
template<class A, class B>
ostream& operator<<(ostream& o, pair<A, B> p){
return o << '(' << p.ff << ',' << p.ss << ')';
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> prime, lpf(n + 1, -1);
for(int i = 2; i <= n; i++){
if(lpf[i] == -1){
lpf[i] = i;
prime.pb(i);
}
for(int j : prime){
if((ll)i * j > n) break;
lpf[i * j] = j;
if(j == lpf[i]) break;
}
}
vector<int> ans(n + 1);
vector<int> p(n + 1);
for(int i = 1; i <= n; i++) cin >> p[i];
vector<bool> vst(n + 1);
int maxa = 0;
for(int i = 1; i <= n; i++){
if(vst[i]) continue;
int now = i;
int len = 0;
while(!vst[now]){
vst[now] = true;
len++;
now = p[now];
}
vector<int> tmp(len);
now = 1;
int cnt = 0;
while(!tmp[now]){
cnt++;
tmp[now] = cnt;
now = now * 2 % len;
}
int a = tmp[now] - 1;
maxa = max(maxa, a);
int b = cnt - tmp[now] + 1;
while(b > 1){
int t = lpf[b];
int c = 0;
while(b % t == 0){
c++;
b /= t;
}
ans[t] = max(ans[t], c);
}
}
const ll MOD = 998244353;
ll total = 1;
for(int i = 1; i <= n; i++){
for(int j = 0; j < ans[i]; j++){
total = total * i % MOD;
}
}
total += maxa;
total %= MOD;
cout << total << "\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3612kb
input:
5 3 5 1 2 4
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3748kb
input:
8 7 5 1 6 8 2 3 4
output:
4
result:
ok single line: '4'
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3528kb
input:
1 1
output:
2
result:
wrong answer 1st lines differ - expected: '1', found: '2'