結果
問題 |
No.2428 Returning Shuffle
|
ユーザー |
![]() |
提出日時 | 2023-08-11 19:49:30 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,209 bytes |
コンパイル時間 | 2,246 ms |
コンパイル使用メモリ | 212,084 KB |
最終ジャッジ日時 | 2025-02-16 00:50:58 |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 WA * 4 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; template<class T> using vec = vector<T>; template<class T, size_t S> using arr = array<T, S>; int main(){ vec<ll> A, S; ll N, M, T; set<ll> L; cin >> N >> M; for (ll n = 0; n <= N; n++) A.emplace_back(n); for (ll m = 0; m < M; m++) { cin >> T; S.resize(T); for (ll t = 0; t < T; t++) cin >> S[t]; S.emplace_back(0); for (ll t = T - 1; t >= 0; t--) A[S[t + 1]] = A[S[t]]; A[S[0]] = A[0]; } for (ll n = 1; n <= N; n++) if (A[n] != n) { ll now = n, d = 1, next; while (A[now] != n) { d++; next = A[now]; A[now] = now; now = next; } A[now] = now; L.emplace(d); } vec<bool> P(1001, true); P[0] = P[1] = false; for (ll n = 2; n <= 1000; n++) if (P[n]) for (ll t = 2 * n; t <= 1000; t += n) P[t] = false; map<ll, ll> ans_fac; for (auto e : L) { ll rt = sqrt(e); map<ll, ll> fac; for (ll p = 2; p < rt; p++) if (P[p]) while (e % p == 0) fac[p]++, e /= p; fac[e]++; for (auto& i : fac) if (ans_fac[i.first] < i.second) ans_fac[i.first] = i.second; } ll ans = 1; for (auto e : ans_fac) for (ll i = 0; i < e.second; i++) ans = (ans * e.first) % 998244353; cout << ans << endl; return 0; }