結果
問題 | No.2428 Returning Shuffle |
ユーザー |
![]() |
提出日時 | 2023-08-18 22:35:37 |
言語 | C (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 269 ms / 2,000 ms |
コード長 | 1,700 bytes |
コンパイル時間 | 333 ms |
コンパイル使用メモリ | 31,872 KB |
実行使用メモリ | 17,408 KB |
最終ジャッジ日時 | 2024-11-28 08:36:27 |
合計ジャッジ時間 | 3,722 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
ソースコード
#include <stdio.h>long long power_mod (long long a, long long b, long long mod_num) {long long ans = 1LL;if (b > 0LL) {ans = power_mod(a, b/2LL, mod_num);ans = (ans * ans) % mod_num;if (b%2LL == 1LL) {ans = (ans * (a % mod_num)) % mod_num;}}return ans;}int main () {int n = 0;int m = 0;int t = 0;int s = 0;int res = 0;long long ans = 1LL;long long mod_num = 998244353LL;int p[1000000] = {};int flag[1000000] = {};long long cnt[1000001] = {};long long tmpcnt[1000001] = {};res = scanf("%d", &n);for (int i = 0; i < n; i++) {p[i] = i;}res = scanf("%d", &m);for (int i = 0; i < m; i++) {int prev = 0;int s0 = 0;res = scanf("%d", &t);res = scanf("%d", &s);s--;prev = p[s];s0 = s;for (int i = 1; i < t; i++) {int tmp = 0;res = scanf("%d", &s);s--;tmp = p[s];p[s] = prev;prev = tmp;}p[s0] = prev;}for (int i = 0; i < n; i++) {if (flag[i] <= 0) {int tmp = 0;int idx = i;int org = 0;while (flag[idx] <= 0) {flag[idx] = 1;idx = p[idx];tmp++;}org = tmp;for (int p = 2; p*p <= org; p++) {tmpcnt[p] = 0LL;while (tmp%p == 0) {tmpcnt[p] += 1LL;tmp /= p;}if (tmpcnt[p] > cnt[p]) {cnt[p] = tmpcnt[p];}}if (tmp > 1 && cnt[tmp] < 1) {cnt[tmp] = 1;}}}for (int i = 2; i <= n; i++) {ans *= power_mod((long long)i, cnt[i], mod_num);ans %= mod_num;}printf("%lld\n", ans);return 0;}