結果
| 問題 |
No.2428 Returning Shuffle
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-08-18 23:01:22 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 149 ms / 2,000 ms |
| コード長 | 1,677 bytes |
| コンパイル時間 | 1,854 ms |
| コンパイル使用メモリ | 206,468 KB |
| 最終ジャッジ日時 | 2025-02-16 10:36:53 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/modint>
using namespace std;
using mint = atcoder::modint998244353;
int main() {
cin.tie(0); cout.tie(0);
ios::sync_with_stdio(false);
int N, M;
cin >> N >> M;
vector<int> P(N);
for(int i = 0; i < N; i++) {
P[i] = i;
}
while(M--) {
int T;
cin >> T;
vector<int> S(T);
for(int i = 0; i < T; i++) {
cin >> S[i];
--S[i];
}
int fi = P[S.back()];
for(int i = T - 1; i > 0; i--) {
P[S[i]] = P[S[i - 1]];
}
P[S.front()] = fi;
//for(int i = 0; i < N; i++) cout << P[i] << " \n"[i == N - 1];
}
bool ok = true;
for(int i = 0; i < N; i++) {
if(P[i] != i) {
ok = false;
}
}
if(ok) {
cout << 1 << '\n';
} else {
vector<bool> dist(N, false);
map<int, int> mp;
for(int i = 0; i < N; i++) {
if(!dist[i]) {
int now = i;
int cnt = 0;
while(!dist[now]) {
dist[now] = true;
now = P[now];
cnt++;
}
if(cnt > 1) {
int T = cnt;
for(int j = 2; j * j <= cnt; j++) {
if(T % j == 0) {
int c = 0;
while(T % j == 0) {
c++;
T /= j;
}
if(mp.count(j) == 0) {
mp[j] = c;
} else {
mp[j] = max(mp[j], c);
}
}
}
if(T > 1) {
if(mp.count(T) == 0) {
mp[T] = 1;
}
}
}
}
}
mint ans = 1;
for(auto [p, q] : mp) {
ans *= mint(p).pow(q);
}
cout << ans.val() << '\n';
}
return 0;
}