結果

問題 No.2428 Returning Shuffle
ユーザー Ping Chung ChangPing Chung Chang
提出日時 2023-08-28 20:09:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 186 ms / 2,000 ms
コード長 1,358 bytes
コンパイル時間 1,679 ms
コンパイル使用メモリ 177,044 KB
実行使用メモリ 38,500 KB
最終ジャッジ日時 2023-08-28 20:10:09
合計ジャッジ時間 4,263 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
7,468 KB
testcase_01 AC 185 ms
38,500 KB
testcase_02 AC 186 ms
37,544 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 129 ms
32,280 KB
testcase_20 AC 129 ms
32,748 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 118 ms
11,328 KB
testcase_25 AC 116 ms
11,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second

map<int,int> dec(int k){
	bool flag = true;
	map<int,int> re;
	while(flag){
		flag = false;
		for(int i = 2;i*i<=k;i++){
			if(k%i == 0){
				while(k%i == 0){
					k/=i;
					re[i]++;
				}
				flag = true;
				break;
			}
		}
	}
	if(k != 1)re[k]++;
	return re;
}

const int mxn = 1e6+10;
const ll mod = 998244353;

inline ll pw(ll a,ll b){
	ll re = 1;
	while(b){
		if(b&1)re = re*a%mod;
		b>>=1;
		a = a*a%mod;
	}
	return re;
}

bitset<mxn> vis;

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll n,m;
	cin>>n>>m;
	int arr[n+1];
	for(int i = 1;i<=n;i++)arr[i] = i;
	for(int i = 0;i<m;i++){
		int t;
		cin>>t;
		int brr[t];
		for(int j = 0;j<t;j++)cin>>brr[j];
		for(int j = t-1;j>=1;j--){
			swap(arr[brr[j-1]],arr[brr[j]]);
		}
	}
	map<int,int> now;
	vector<map<int,int>> v;
	for(int i = 1;i<=n;i++){
		if(vis[i])continue;
		int C = 0,now = i;
		do{
			vis[now] = true;
			C++;
			now = arr[now];
		}while(!vis[now]);
		v.push_back(dec(C));
	}
	for(auto &i:v){
		for(auto &j:i){
			now[j.fs] = max(now[j.fs],j.sc);
		}
	}
	ll ans = 1;
	for(auto &i:now)ans = ans*pw(i.fs,i.sc)%mod;
	cout<<ans;
	return 0;
}
0