結果

問題 No.2428 Returning Shuffle
ユーザー pengin_2000pengin_2000
提出日時 2023-08-18 22:28:34
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,112 bytes
コンパイル時間 717 ms
コンパイル使用メモリ 29,332 KB
実行使用メモリ 29,252 KB
最終ジャッジ日時 2023-08-18 22:28:39
合計ジャッジ時間 3,601 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 1 ms
7,936 KB
testcase_04 AC 1 ms
7,972 KB
testcase_05 AC 2 ms
7,940 KB
testcase_06 AC 2 ms
7,932 KB
testcase_07 AC 1 ms
7,876 KB
testcase_08 AC 1 ms
8,000 KB
testcase_09 AC 1 ms
7,988 KB
testcase_10 AC 2 ms
8,000 KB
testcase_11 AC 2 ms
8,060 KB
testcase_12 AC 2 ms
7,924 KB
testcase_13 AC 2 ms
8,064 KB
testcase_14 AC 2 ms
7,976 KB
testcase_15 AC 2 ms
7,940 KB
testcase_16 AC 2 ms
7,876 KB
testcase_17 AC 2 ms
8,060 KB
testcase_18 AC 2 ms
7,936 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 2 ms
7,940 KB
testcase_22 AC 2 ms
7,996 KB
testcase_23 AC 2 ms
7,964 KB
testcase_24 AC 145 ms
26,356 KB
testcase_25 AC 167 ms
26,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
long long int gcd(long long int a, long long int b)
{
	long long int r = a % b;
	while (r > 0)
	{
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}
long long int lcm(long long int a, long long int b, long long int p)
{
	return a / gcd(a, b) * b % p;
}
long long int t[500005], s[1000006];
long long int p[1000006];
long long int used[1000006];
int main()
{
	long long int n, m;
	scanf("%lld %lld", &n, &m);
	t[0] = 0;
	long long int i, j, k;
	for (i = 0; i < m; i++)
	{
		scanf("%lld", &t[i + 1]);
		t[i + 1] += t[i];
		for (j = t[i]; j < t[i + 1]; j++)
		{
			scanf("%lld", &s[j]);
			s[j]--;
		}
	}
	for (i = 0; i < n; i++)
		p[i] = i;
	for (i = 0; i < m; i++)
	{
		k = p[s[t[i + 1] - 1]];
		for (j = t[i + 1] - 1; j > t[i]; j--)
			p[s[j]] = p[s[j - 1]];
		p[s[t[i]]] = k;
 	}
	long long int ans = 1, cnt;
	const long long int prime = 998244353;
	for (i = 0; i < n; i++)
		used[i] = 0;
	for (i = 0; i < n; i++)
	{
		if (used[i] > 0)
			continue;
		for (j = i, cnt = 0; used[j] == 0; j = p[j])
		{
			used[j]++;
			cnt++;
		}
		ans = lcm(ans, cnt, prime);
	}
	printf("%lld\n", ans);
	return 0;
}
0