結果

問題 No.2428 Returning Shuffle
ユーザー shobonvipshobonvip
提出日時 2023-08-18 21:58:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 445 ms / 2,000 ms
コード長 1,697 bytes
コンパイル時間 4,427 ms
コンパイル使用メモリ 263,372 KB
実行使用メモリ 15,104 KB
最終ジャッジ日時 2024-05-06 03:59:13
合計ジャッジ時間 8,113 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 314 ms
15,104 KB
testcase_01 AC 445 ms
15,104 KB
testcase_02 AC 443 ms
15,104 KB
testcase_03 AC 8 ms
7,168 KB
testcase_04 AC 9 ms
7,296 KB
testcase_05 AC 9 ms
7,168 KB
testcase_06 AC 8 ms
7,168 KB
testcase_07 AC 9 ms
7,168 KB
testcase_08 AC 8 ms
7,168 KB
testcase_09 AC 9 ms
7,296 KB
testcase_10 AC 9 ms
7,168 KB
testcase_11 AC 9 ms
7,296 KB
testcase_12 AC 9 ms
7,168 KB
testcase_13 AC 9 ms
7,168 KB
testcase_14 AC 8 ms
7,296 KB
testcase_15 AC 8 ms
7,296 KB
testcase_16 AC 8 ms
7,296 KB
testcase_17 AC 8 ms
7,296 KB
testcase_18 AC 8 ms
7,168 KB
testcase_19 AC 334 ms
14,976 KB
testcase_20 AC 363 ms
15,104 KB
testcase_21 AC 9 ms
7,168 KB
testcase_22 AC 8 ms
7,296 KB
testcase_23 AC 9 ms
7,168 KB
testcase_24 AC 347 ms
14,988 KB
testcase_25 AC 361 ms
14,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/

/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/

typedef long long ll;

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)

template <typename T> bool chmin(T &a, const T &b) {
	if (a <= b) return false;
	a = b;
	return true;
}

template <typename T> bool chmax(T &a, const T &b) {
	if (a >= b) return false;
	a = b;
	return true;
}

template <typename T> T max(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
	return ret;
}

template <typename T> T min(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
	return ret;
}

template <typename T> T sum(vector<T> &a){
	T ret = 0;
	for (int i=0; i<(int)a.size(); i++) ret += a[i];
	return ret;
}

int main(){
	int n, m; cin >> n >> m;
	vector<int> a(n);
	iota(a.begin(), a.end(), 0);
	while(m--){
		int t; cin >> t;
		vector<int> g(t);
		rep(i,0,t){
			cin >> g[i];
			g[i]--;
		}
		rrep(i,0,t-1){
			swap(a[g[i]], a[g[i+1]]);
		}
	}
	dsu uf(n);
	rep(i,0,n){
		uf.merge(a[i], i);
	}
	int mx = 1e6 + 50;
	vector<int> r(mx);
	rep(i,0,n){
		if (uf.leader(i) == i){
			int v = uf.size(i);
			int j = 2;
			while (v > 1){
				if (v % j == 0){
					int cnt = 0;
					while (v % j == 0){
						v /= j;
						cnt++;
					}
					chmax(r[j], cnt);
				}
				j++;
			}
		}
	}
	mint ans = 1;
	rep(i,1,mx){
		ans *= mint(i).pow(r[i]);
	}
	cout << ans.val() << '\n';
}

0