結果

問題 No.2428 Returning Shuffle
ユーザー bortikbortik
提出日時 2023-08-19 01:52:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 440 ms / 2,000 ms
コード長 1,586 bytes
コンパイル時間 2,181 ms
コンパイル使用メモリ 215,304 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-05-06 09:02:04
合計ジャッジ時間 6,137 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 282 ms
7,296 KB
testcase_01 AC 440 ms
9,484 KB
testcase_02 AC 417 ms
9,480 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 311 ms
9,516 KB
testcase_20 AC 321 ms
9,516 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 310 ms
11,008 KB
testcase_25 AC 305 ms
11,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 k = 1; k < t; k++){
            swap(a[s[k]], 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;
    vector<bool> primes(1001, true);
    primes[0] = false;
    primes[1] = false;
    for(int i = 2; i < 1001;i++) if (primes[i]){
        for(int j = 2*i; j < 1001; j += i) primes[j] = false;
    }
    for(ll x: l){
        map<ll,ll> cur;
        ll e = x;
        ll root = sqrt(x);
        for(int i = 2; i <= root; i++) {
            if(primes[i]){
                while(e % i == 0) {
                    cur[i]++;
                    e /= i;
                }
            }
        }
        cur[e]++;
        for(auto& i: cur) if(lcm[i.first] < i.second) lcm[i.first] = i.second;
    }
    
    for(auto& i: lcm){
        for(ll j = 0; j < i.second; j++){
            answer = (answer*i.first) % 998244353;
        }
    }

    cout << answer;
}
0