結果

問題 No.2428 Returning Shuffle
ユーザー 👑 kmjpkmjp
提出日時 2023-08-18 23:16:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 357 ms / 2,000 ms
コード長 2,074 bytes
コンパイル時間 2,387 ms
コンパイル使用メモリ 206,048 KB
実行使用メモリ 53,496 KB
最終ジャッジ日時 2023-08-18 23:16:17
合計ジャッジ時間 6,795 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
46,680 KB
testcase_01 AC 318 ms
46,576 KB
testcase_02 AC 342 ms
46,404 KB
testcase_03 AC 19 ms
41,320 KB
testcase_04 AC 19 ms
41,480 KB
testcase_05 AC 19 ms
41,332 KB
testcase_06 AC 18 ms
41,420 KB
testcase_07 AC 18 ms
41,316 KB
testcase_08 AC 20 ms
41,460 KB
testcase_09 AC 19 ms
41,432 KB
testcase_10 AC 19 ms
41,320 KB
testcase_11 AC 19 ms
41,540 KB
testcase_12 AC 19 ms
41,316 KB
testcase_13 AC 20 ms
41,428 KB
testcase_14 AC 19 ms
41,448 KB
testcase_15 AC 19 ms
41,332 KB
testcase_16 AC 19 ms
41,332 KB
testcase_17 AC 20 ms
41,476 KB
testcase_18 AC 19 ms
41,444 KB
testcase_19 AC 245 ms
46,508 KB
testcase_20 AC 273 ms
46,432 KB
testcase_21 AC 18 ms
41,360 KB
testcase_22 AC 19 ms
41,320 KB
testcase_23 AC 19 ms
41,496 KB
testcase_24 AC 356 ms
52,936 KB
testcase_25 AC 357 ms
53,496 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N,M;
int P[1010101];

template<int um> class UF {
	public:
	vector<int> par,rank,cnt,G[um];
	UF() {par=rank=vector<int>(um,0); cnt=vector<int>(um,1); for(int i=0;i<um;i++) par[i]=i;}
	void reinit(int num=um) {int i; FOR(i,num) rank[i]=0,cnt[i]=1,par[i]=i;}
	int operator[](int x) {return (par[x]==x)?(x):(par[x] = operator[](par[x]));}
	int count(int x) { return cnt[operator[](x)];}
	int operator()(int x,int y) {
		if((x=operator[](x))==(y=operator[](y))) return x;
		cnt[y]=cnt[x]=cnt[x]+cnt[y];
		if(rank[x]>rank[y]) return par[x]=y;
		rank[x]+=rank[x]==rank[y]; return par[y]=x;
	}
	void dump(int num=um) { //グループ分けした配列を作る
		int i;
		FOR(i,num) G[i].clear();
		FOR(i,num) G[operator[](i)].push_back(i);
	}
};
UF<1010101> uf;
int num[1010101];
const ll mo=998244353;
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(i,N) P[i]=i;
	while(M--) {
		cin>>x;
		vector<int> S(x),V;
		FOR(i,x) {
			cin>>y;
			S[i]=y-1;
			V.push_back(P[S[i]]);
		}
		FOR(i,x) P[S[(i+1)%x]]=V[i];
	}
	FOR(i,N) uf(i,P[i]);
	FOR(i,N) if(uf[i]==i) {
		x=uf.count(i);
		for(y=2;y<=x;y++) if(x%y==0) {
			k=0;
			while(x%y==0) k++, x/=y;
			num[y]=max(num[y],k);
		}
	}
	ll ret=1;
	for(i=2;i<=N;i++) while(num[i]--) ret=ret*i%mo;
	cout<<ret<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0