結果

問題 No.2428 Returning Shuffle
ユーザー bortikbortik
提出日時 2023-08-19 01:40:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,559 bytes
コンパイル時間 2,527 ms
コンパイル使用メモリ 215,248 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-05-06 08:49:30
合計ジャッジ時間 7,016 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 315 ms
7,424 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 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 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 WA -
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 360 ms
11,068 KB
testcase_25 AC 343 ms
11,136 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 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(ll x: l){
        map<ll,ll> cur;
        ll 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(ll j = 0; j < i.second; j++){
            answer = (answer*i.first) % 998244353;
        }
    }

    cout << answer;
}
0