結果

問題 No.2428 Returning Shuffle
ユーザー kuronikuroni
提出日時 2023-08-18 21:44:16
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 205 ms / 2,000 ms
コード長 1,410 bytes
コンパイル時間 3,347 ms
コンパイル使用メモリ 246,816 KB
実行使用メモリ 14,876 KB
最終ジャッジ日時 2023-08-18 21:44:45
合計ジャッジ時間 5,994 ms
ジャッジサーバーID
(参考情報)
judge9 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 109 ms
14,712 KB
testcase_01 AC 176 ms
14,700 KB
testcase_02 AC 205 ms
14,716 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,504 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 5 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 132 ms
14,616 KB
testcase_20 AC 138 ms
14,716 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 137 ms
14,872 KB
testcase_25 AC 140 ms
14,876 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using mint = modint998244353;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m; cin >> n >> m;
    vector<int> p(n);
    iota(p.begin(), p.end(), 0);
    while (m--) {
        int k; cin >> k;
        vector<int> pos(k);
        for (int i = 0; i < k; i++) {
            cin >> pos[i]; pos[i]--;
        }
        int st = p[pos[k - 1]];
        for (int i = k - 1; i > 0; i--) {
            p[pos[i]] = p[pos[i - 1]];
        }
        p[pos[0]] = st;
    }
    vector<int> fct(n + 1), cnt(n + 1);
    for (int i = 2; i <= n; i++) {
        if (fct[i] == 0) {
            fct[i] = i;
            for (int j = i; 1LL * j * i <= n; j++) {
                fct[i * j] = i;
            }
        }
    }
    for (int i = 0; i < n; i++) {
        if (p[i] != -1) {
            int cur = -1;
            for (int u = i; u != -1; cur++) {
                int v = p[u]; p[u] = -1; u = v;
            }
            for (; cur != 1; ) {
                int d = fct[cur], cd = 0;
                while (cur % d == 0) {
                    cd++;
                    cur /= d;
                }
                cnt[d] = max(cnt[d], cd);
            }
        }
    }
    mint ans = 1;
    for (int i = 2; i <= n; i++) {
        ans *= mint(i).pow(cnt[i]);
    }
    cout << ans.val();
}
0