結果

問題 No.2428 Returning Shuffle
ユーザー polylogKpolylogK
提出日時 2023-09-28 15:59:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 255 ms / 2,000 ms
コード長 1,960 bytes
コンパイル時間 2,467 ms
コンパイル使用メモリ 207,148 KB
実行使用メモリ 14,864 KB
最終ジャッジ日時 2023-09-28 15:59:58
合計ジャッジ時間 6,404 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 136 ms
14,744 KB
testcase_01 AC 255 ms
14,732 KB
testcase_02 AC 255 ms
14,836 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 177 ms
14,844 KB
testcase_20 AC 184 ms
14,844 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 200 ms
14,864 KB
testcase_25 AC 215 ms
14,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

#if defined(DONLINE_JUDGE)
#define NDEBUG
#elif defined(ONLINE_JUDGE)
#define NDEBUG
#endif

template <typename T>
std::vector<T> make_v(size_t a) {
    return std::vector<T>(a);
}
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return std::vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

int main() {
    int n, m;
    scanf("%d%d", &n, &m);

    std::vector<int> p(n);
    std::iota(p.begin(), p.end(), 0);

    for (int i = 0; i < m; ++i) {
        int t;
        scanf("%d", &t);

        std::vector<int> s(t);
        for (auto& v : s) scanf("%d", &v), --v;

        const int o = p[s.back()];
        for (int j = t - 1; j > 0; --j) {
            p[s[j]] = p[s[j - 1]];
        }
        p[s.front()] = o;
    }

    std::vector<int> minp(n + 1, -1);
    for (int p = 2; p <= n; ++p) {
        if (minp[p] != -1) continue;

        for (int i = p; i <= n; i += p) {
            if (minp[i] != -1) continue;

            minp[i] = p;
        }
    }

    std::map<int, int> lcm;

    std::vector<int> used(n);
    for (int i = 0; i < n; ++i) {
        if (used[i]) continue;
        used[i] = 1;

        int size = 1;
        {
            int now = p[i];
            while (now != i) {
                ++size;
                used[now] = 1;

                now = p[now];
            }
        }

        while (size != 1) {
            const int p = minp[size];

            int cnt = 0;
            while (size % p == 0) {
                ++cnt;
                size /= p;
            }

            lcm[p] = std::max(lcm[p], cnt);
        }
    }

    const int MOD = 998244353;

    i64 ans = 1;
    for (auto [p, cnt] : lcm) {
        for (int i = 0; i < cnt; ++i) ans = ans * p % MOD;
    }
    printf("%lld\n", ans);
    return 0;
}
0