結果

問題 No.2428 Returning Shuffle
ユーザー noya2noya2
提出日時 2023-08-12 14:55:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 480 ms / 2,000 ms
コード長 1,165 bytes
コンパイル時間 2,306 ms
コンパイル使用メモリ 207,216 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-05-03 00:16:01
合計ジャッジ時間 6,563 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 325 ms
11,136 KB
testcase_01 AC 479 ms
11,136 KB
testcase_02 AC 480 ms
11,136 KB
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 AC 2 ms
5,376 KB
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 1 ms
5,376 KB
testcase_19 AC 352 ms
11,264 KB
testcase_20 AC 350 ms
11,136 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 348 ms
11,020 KB
testcase_25 AC 349 ms
11,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/modint>
using namespace std;
using mint = atcoder::modint998244353;

int main(){
    int n, m; cin >> n >> m;
    vector<int> p(n); iota(p.begin(),p.end(),0);
    while (m--){
        int t; cin >> t;
        vector<int> q(t);
        for (int i = 0; i < t; i++) cin >> q[i], q[i]--;
        reverse(q.begin(),q.end());
        for (int i = 0; i < t-1; i++) swap(p[q[i]],p[q[i+1]]);
    }
    
    vector<bool> done(n,false);
    vector<int> ma(n+1,0);
    for (int i = 0; i < n; i++){
        if (done[i]) continue;
        int len = 1;
        int cur = p[i];
        done[i] = true;
        while (i != cur){
            len++;
            done[cur] = true;
            cur = p[cur];
        }
        for (int d = 2; d * d <= len; d++){
            if (len % d != 0) continue;
            int cnt = 0;
            while (len % d == 0){
                len /= d;
                cnt++;
            }
            ma[d] = max(ma[d],cnt);
        }
        ma[len] = max(ma[len],1);
    }
    mint ans = 1;
    for (int len = 1; len <= n; len++){
        ans *= mint(len).pow(ma[len]);
    }
    cout << ans.val() << endl;
}
0