結果

問題 No.2428 Returning Shuffle
ユーザー 👑 NachiaNachia
提出日時 2023-08-18 21:19:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 239 ms / 2,000 ms
コード長 1,191 bytes
コンパイル時間 990 ms
コンパイル使用メモリ 85,884 KB
実行使用メモリ 15,104 KB
最終ジャッジ日時 2024-05-06 03:04:24
合計ジャッジ時間 3,811 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
15,104 KB
testcase_01 AC 239 ms
14,848 KB
testcase_02 AC 239 ms
14,976 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 2 ms
5,376 KB
testcase_19 AC 163 ms
14,976 KB
testcase_20 AC 160 ms
14,976 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 156 ms
15,008 KB
testcase_25 AC 162 ms
14,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <atcoder/modint>
#include <atcoder/dsu>
using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
const i64 INF = 1001001001001001001;

using Modint = atcoder::static_modint<998244353>;

int Gcd(int a, int b){ return b ? Gcd(b, a%b) : a; }

int main(){
    int N, M; cin >> N >> M;
    vector<int> P(N);
    rep(i,N) P[i] = i;
    rep(j,M){
        int n; cin >> n;
        vector<int> F(n);
        rep(i,n){ int a; cin >> a; F[i] = a-1; }
        for(int i=n-2; i>=0; i--) swap(P[F[i]], P[F[i+1]]);
    }
    atcoder::dsu G(N);
    rep(i,N) G.merge(P[i], i);
    vector<int> Q(N+1);
    rep(i,N) Q[G.size(i)] = 1;
    vector<int> QC;
    rep(i,N+1) if(Q[i]){
        int x = i;
        for(int q : QC) x /= Gcd(x, q);
        QC.push_back(x);
    }
    Modint ans = 1;
    for(auto x : QC) ans *= x;
    cout << ans.val() << endl;
    return 0;
}


struct ios_do_not_sync{
    ios_do_not_sync(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
    }
} ios_do_not_sync_instance;

0