結果

問題 No.2428 Returning Shuffle
ユーザー eve__fuyuki
提出日時 2024-06-13 01:37:13
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 411 ms / 2,000 ms
コード長 1,327 bytes
コンパイル時間 3,404 ms
コンパイル使用メモリ 213,688 KB
最終ジャッジ日時 2025-02-21 21:28:00
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
#include <atcoder/dsu>
#include <atcoder/modint>
using namespace atcoder;
using mint = modint998244353;
void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

int main() {
    fast_io();
    int n, m;
    cin >> n >> m;
    vector<int> p(n);
    iota(p.begin(), p.end(), 0);
    for (int i = 0; i < m; i++) {
        int t;
        cin >> t;
        vector<int> s(t);
        vector<int> q(t);
        for (int j = 0; j < t; j++) {
            cin >> s[j];
            s[j]--;
            q[j] = p[s[j]];
        }
        for (int j = 0; j < t; j++) {
            p[s[(j + 1) % t]] = q[j];
        }
    }
    dsu uf(n);
    for (int i = 0; i < n; i++) {
        uf.merge(i, p[i]);
    }
    map<int, int> cnt;
    for (auto gr : uf.groups()) {
        int sz = gr.size();
        for (int i = 2; i * i <= sz; i++) {
            if (sz % i != 0) continue;
            int c = 0;
            while (sz % i == 0) {
                sz /= i;
                c++;
            }
            cnt[i] = max(cnt[i], c);
        }
        if (sz > 1) {
            cnt[sz] = max(cnt[sz], 1);
        }
    }
    mint ans = 1;
    for (auto [p, c] : cnt) {
        for (int i = 0; i < c; i++) {
            ans *= p;
        }
    }
    cout << ans.val() << endl;
}
0