結果
問題 |
No.2428 Returning Shuffle
|
ユーザー |
![]() |
提出日時 | 2023-08-19 01:37:56 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,562 bytes |
コンパイル時間 | 1,953 ms |
コンパイル使用メモリ | 208,016 KB |
最終ジャッジ日時 | 2025-02-16 11:18:17 |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 WA * 5 |
ソースコード
#include<bits/stdc++.h> using namespace std; #define ll long long int main(){ int n,m; cin >> n >> m; vector<int> a(n); iota(a.begin(), a.end(), 0); for(int i = 0; i < m; i++){ int t; cin >> t; vector<int> s(t); for(int j = 0; j < t; j++){ int x; cin >> x; s[j] = x-1; } int p = s[0]; for(int i = 1; i < t; i++){ swap(a[s[i]], a[p]); } } vector<int> l; vector<bool> seen(n, false); for(int i = 0; i < n; i++){ if(seen[i]) continue; seen[i] = true; int cur = a[i]; int len = 1; while(cur != i){ len++; seen[cur] = true; cur = a[cur]; } l.push_back(len); } map<ll,ll> lcm; ll answer = 1; bool primes[1001] = {1}; primes[0] = false; primes[1] = false; for(int i = 2; i < 1001;i++) if (primes[i]){ for(int j = 2; j*i < 1001; j++) primes[j*i] = false; } for(int x: l){ map<ll,ll> cur; int root = sqrt(x); for(int i = 2; i <= root; i++) { if(primes[i]){ while(x % i == 0) { cur[i]++; x /= i; } } } cur[x]++; for(auto& i: cur) if(lcm[i.first] < i.second) lcm[i.first] = i.second; } for(auto& i: lcm){ for(int j = 0; j < i.second; j++){ answer = (answer*i.first) % 998244353; } } cout << answer; }