結果

問題 No.2428 Returning Shuffle
ユーザー kotatsugamekotatsugame
提出日時 2023-08-18 21:49:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 165 ms / 2,000 ms
コード長 979 bytes
コンパイル時間 748 ms
コンパイル使用メモリ 72,888 KB
実行使用メモリ 16,384 KB
最終ジャッジ日時 2024-05-06 03:48:41
合計ジャッジ時間 3,395 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
12,544 KB
testcase_01 AC 164 ms
12,416 KB
testcase_02 AC 165 ms
12,544 KB
testcase_03 AC 13 ms
7,424 KB
testcase_04 AC 14 ms
7,552 KB
testcase_05 AC 13 ms
7,424 KB
testcase_06 AC 12 ms
7,424 KB
testcase_07 AC 14 ms
7,552 KB
testcase_08 AC 13 ms
7,552 KB
testcase_09 AC 13 ms
7,552 KB
testcase_10 AC 12 ms
7,552 KB
testcase_11 AC 14 ms
7,552 KB
testcase_12 AC 14 ms
7,680 KB
testcase_13 AC 13 ms
7,424 KB
testcase_14 AC 14 ms
7,424 KB
testcase_15 AC 13 ms
7,552 KB
testcase_16 AC 14 ms
7,552 KB
testcase_17 AC 13 ms
7,552 KB
testcase_18 AC 12 ms
7,424 KB
testcase_19 AC 133 ms
12,672 KB
testcase_20 AC 130 ms
12,544 KB
testcase_21 AC 12 ms
7,424 KB
testcase_22 AC 13 ms
7,552 KB
testcase_23 AC 12 ms
7,552 KB
testcase_24 AC 136 ms
16,256 KB
testcase_25 AC 134 ms
16,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>
#include<cassert>
#include<atcoder/modint>
using namespace std;
int N,M;
int P[1<<20];
int S[1<<20];
bool vis[1<<20];
int lsp[1<<20];
int cnt[1<<20];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	for(int i=2;i<1<<20;i++)if(lsp[i]==0)
	{
		for(int j=i;j<1<<20;j+=i)lsp[j]=i;
	}
	cin>>N>>M;
	for(int i=0;i<N;i++)P[i]=i;
	for(;M--;)
	{
		int T;cin>>T;
		for(int i=0;i<T;i++)
		{
			cin>>S[i];
			S[i]--;
		}
		int cur=P[S[T-1]];
		for(int i=T-1;i--;)
		{
			P[S[i+1]]=P[S[i]];
		}
		P[S[0]]=cur;
		//for(int i=0;i<N;i++)cout<<P[i]<<" ";cout<<endl;
	}
	for(int i=0;i<N;i++)if(!vis[i])
	{
		int u=i,sz=0;
		while(!vis[u])
		{
			vis[u]=true;
			u=P[u];
			sz++;
		}
		while(sz>1)
		{
			int p=lsp[sz],c=0;
			while(sz%p==0)sz/=p,c++;
			cnt[p]=max(cnt[p],c);
		}
	}
	using mint=atcoder::modint998244353;
	mint ans=1;
	for(int i=2;i<1<<20;i++)if(cnt[i]>0)ans*=mint::raw(i).pow(cnt[i]);
	cout<<ans.val()<<endl;
}
0