結果

問題 No.2428 Returning Shuffle
ユーザー 👑 chro_96chro_96
提出日時 2023-08-18 22:35:37
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 194 ms / 2,000 ms
コード長 1,700 bytes
コンパイル時間 542 ms
コンパイル使用メモリ 31,744 KB
実行使用メモリ 17,408 KB
最終ジャッジ日時 2024-05-06 04:56:07
合計ジャッジ時間 3,298 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
17,280 KB
testcase_01 AC 194 ms
17,408 KB
testcase_02 AC 192 ms
17,408 KB
testcase_03 AC 11 ms
17,280 KB
testcase_04 AC 12 ms
17,408 KB
testcase_05 AC 11 ms
17,408 KB
testcase_06 AC 11 ms
17,280 KB
testcase_07 AC 11 ms
17,408 KB
testcase_08 AC 12 ms
17,408 KB
testcase_09 AC 11 ms
17,408 KB
testcase_10 AC 11 ms
17,408 KB
testcase_11 AC 12 ms
17,408 KB
testcase_12 AC 11 ms
17,408 KB
testcase_13 AC 11 ms
17,408 KB
testcase_14 AC 11 ms
17,408 KB
testcase_15 AC 12 ms
17,408 KB
testcase_16 AC 11 ms
17,408 KB
testcase_17 AC 11 ms
17,408 KB
testcase_18 AC 11 ms
17,408 KB
testcase_19 AC 159 ms
17,408 KB
testcase_20 AC 158 ms
17,408 KB
testcase_21 AC 12 ms
17,408 KB
testcase_22 AC 11 ms
17,408 KB
testcase_23 AC 11 ms
17,408 KB
testcase_24 AC 162 ms
17,408 KB
testcase_25 AC 162 ms
17,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0