結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 3 ms
10,068 KB
testcase_04 AC 2 ms
10,068 KB
testcase_05 AC 2 ms
9,980 KB
testcase_06 WA -
testcase_07 AC 3 ms
9,972 KB
testcase_08 AC 3 ms
9,972 KB
testcase_09 WA -
testcase_10 AC 2 ms
9,972 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 2 ms
10,076 KB
testcase_15 AC 2 ms
9,972 KB
testcase_16 AC 3 ms
9,884 KB
testcase_17 AC 2 ms
10,064 KB
testcase_18 AC 3 ms
9,972 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 2 ms
9,984 KB
testcase_22 AC 2 ms
9,996 KB
testcase_23 AC 2 ms
10,076 KB
testcase_24 AC 233 ms
28,400 KB
testcase_25 AC 259 ms
28,312 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 t[500005], s[1000006];
long long int p[1000006];
long long int used[1000006];
long long int cyc[1000006], cc;
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 cnt;
	const long long int prime = 998244353;
	for (i = 0; i < n; i++)
		used[i] = 0;
	cc = 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++;
		}
		cyc[cc] = cnt;
		cc++;
	}
	long long int g = cyc[0];
	for (i = 0; i < cc; i++)
		g = gcd(g, cyc[i]);
	long long int ans = g;
	for (i = 0; i < cc; i++)
		ans = cyc[i] / g * ans % prime;
	printf("%lld\n", ans);
	return 0;
}
0