結果

問題 No.2428 Returning Shuffle
ユーザー Today03Today03
提出日時 2023-08-18 23:09:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 722 ms / 2,000 ms
コード長 1,372 bytes
コンパイル時間 2,935 ms
コンパイル使用メモリ 219,168 KB
実行使用メモリ 198,664 KB
最終ジャッジ日時 2024-05-06 05:41:54
合計ジャッジ時間 8,510 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 359 ms
39,048 KB
testcase_01 AC 654 ms
47,760 KB
testcase_02 AC 666 ms
48,660 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 562 ms
90,928 KB
testcase_20 AC 564 ms
99,760 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 699 ms
198,664 KB
testcase_25 AC 722 ms
198,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/modint>
using mint = atcoder::modint998244353;
#include <atcoder/scc>

vector<pair<long long, int>> prime_factorize(long long n) {
  vector<pair<long long, int>> ret;
  for (long long i = 2; i * i <= n; i++) {
    if (n % i != 0) {
      continue;
    }
    int ex = 0;
    while (n % i == 0) {
      ex++;
      n /= i;
    }
    ret.push_back({i, ex});
  }
  if (n != 1) {
    ret.push_back({n, 1});
  }
  return ret;
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> p(n);
  iota(p.begin(), p.end(), 0);
  for (int i = 0; i < m; i++) {
    int t;
    cin >> t;
    vector<int> s(t);
    for (int j = 0; j < t; j++) {
      cin >> s[j];
      s[j]--;
    }
    int start = p[s[t - 1]];
    for (int j = t - 2; j >= 0; j--) {
      p[s[j + 1]] = p[s[j]];
    }
    p[s[0]] = start;
  }
  atcoder::scc_graph g(n);
  int ed = 0;
  for (int i = 0; i < n; i++) {
    if (i == p[i]) {
      continue;
    }
    ed++;
    g.add_edge(i, p[i]);
  }
  auto res = g.scc();
  vector<int> ps(n + 1);
  for (auto x : res) {
    auto pf = prime_factorize(x.size());
    for (auto [p, e] : pf) {
      ps[p] = max(ps[p], e);
    }
  }
  mint ans = 1;
  for (int i = 1; i <= n; i++) {
    mint add = 1;
    for (int j = 0; j < ps[i]; j++) {
      add *= i;
    }
    ans *= add;
  }
  cout << ans.val() << endl;
}
0