結果

問題 No.2428 Returning Shuffle
ユーザー 👑 potato167potato167
提出日時 2023-08-15 21:45:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 437 ms / 2,000 ms
コード長 784 bytes
コンパイル時間 2,012 ms
コンパイル使用メモリ 203,836 KB
実行使用メモリ 15,104 KB
最終ジャッジ日時 2024-05-03 08:15:56
合計ジャッジ時間 7,089 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 293 ms
14,976 KB
testcase_01 AC 437 ms
14,976 KB
testcase_02 AC 416 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 1 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 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 1 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 315 ms
15,104 KB
testcase_20 AC 311 ms
15,068 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 312 ms
14,976 KB
testcase_25 AC 320 ms
14,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(p) p.begin(),p.end()
#define rep(i,a,b) for(int i=(int)a;i<(int)b;i++)
const int mod=998244353;

int main(){
	int N,M;
	cin>>N>>M;
	vector<int> p(N);
	rep(i,0,N) p[i]=i;
	rep(i,0,M){
		int T;cin>>T;
		vector<int> S(T);
		rep(j,0,T) cin>>S[j],S[j]--;
		vector<int> tmp(T);
		rep(j,0,T) tmp[j]=p[S[j]];
		for(int j=T-2;j>=0;j--) swap(tmp[j+1],tmp[j]);
		rep(j,0,T) p[S[j]]=tmp[j];
	}
	vector<int> q(N+1),seen(N);
	rep(i,0,N){
		if(seen[i]) continue;
		int C=0,tmp=0;
		while(seen[i]==0) C++,seen[i]=1,i=p[i];
		for(int j=2;j*j<=C;j++){
			tmp=0;
			while(C%j==0) C/=j,tmp++;
			q[j]=max(q[j],tmp);
		}
		if(C!=1) q[C]=max(q[C],1);
	}
	ll ans=1;
	rep(i,1,N+1) rep(j,0,q[i]) ans=ans*i%mod;
	cout<<ans<<"\n";
}
0