結果

問題 No.2428 Returning Shuffle
ユーザー nono00nono00
提出日時 2023-08-18 22:40:33
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 175 ms / 2,000 ms
コード長 2,155 bytes
コンパイル時間 3,019 ms
コンパイル使用メモリ 259,900 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-05-06 05:01:27
合計ジャッジ時間 5,229 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
7,296 KB
testcase_01 AC 175 ms
7,232 KB
testcase_02 AC 170 ms
7,304 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 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 117 ms
7,168 KB
testcase_20 AC 117 ms
7,168 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 119 ms
10,964 KB
testcase_25 AC 122 ms
11,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

namespace nono {

constexpr long long mod = 998244353;

std::vector<std::pair<int, int>> factorize(int n) {
    std::vector<std::pair<int, int>> result;
    for (long long i = 2; i * i <= n; i++) {
        int count = 0;
        while (n % i == 0) {
            n /= i;
            count++;
        }
        if (count > 0) {
            result.emplace_back(i, count);
        }
    }
    if (n != 1) {
        result.emplace_back(n, 1);
    }
    return result;
}

long long pow(long long base, long long exp, long long mod) {
    long long result = 1;
    while (exp > 0) {
        if (exp & 1) {
            result *= base;
            result %= mod;
        }
        base *= base;
        base %= mod;
        exp >>= 1;
    }
    return result;
}

void solve() {
    int n, m;
    std::cin >> n >> m;
    std::vector<int> a(n);
    std::iota(a.begin(), a.end(), 0);
    for (int i = 0; i < m; i++) {
        int t;
        std::cin >> t;
        std::vector<int> s(t);
        for (int j = 0; j < t; j++) {
            std::cin >> s[j];
            s[j]--;
        }
        int temp = a[s.back()];
        for (int j = t - 1; j > 0; j--) {
            a[s[j]] = a[s[j - 1]];
        }
        a[s.front()] = temp;
    }

    //  for (int i = 0; i < n; i++) {
    //      std::cout << a[i] << ' ';
    //  }
    //  std::cout << std::endl;

    std::vector<bool> used(n);
    std::map<int, int> mp;
    for (int i = 0; i < n; i++) {
        if (not used[i]) {
            int s = i;
            int len = 0;
            while (not used[s]) {
                used[s] = true;
                s = a[s];
                len++;
            }
            for (const auto& [p, v]: factorize(len)) {
                mp[p] = std::max(mp[p], v);
            }
        }
    }

    long long ans = 1;
    for (const auto& [p, v]: mp) {
        ans *= pow(p, v, mod);
        ans %= mod;
    }
    std::cout << ans << std::endl;
}

}  //  namespace nono

int main() {
    std::cin.tie(0)->sync_with_stdio(0);
    std::cout << std::fixed << std::setprecision(15);

    int t = 1;
    //  std::cin >> t;
    while (t--) nono::solve();
}
0