結果

問題 No.2428 Returning Shuffle
ユーザー tomeruntomerun
提出日時 2023-08-18 21:22:04
言語 Crystal
(1.11.2)
結果
AC  
実行時間 330 ms / 2,000 ms
コード長 473 bytes
コンパイル時間 21,645 ms
コンパイル使用メモリ 260,240 KB
実行使用メモリ 79,500 KB
最終ジャッジ日時 2023-08-18 21:22:39
合計ジャッジ時間 25,025 ms
ジャッジサーバーID
(参考情報)
judge10 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
21,184 KB
testcase_01 AC 330 ms
21,080 KB
testcase_02 AC 324 ms
20,904 KB
testcase_03 AC 3 ms
4,828 KB
testcase_04 AC 2 ms
4,816 KB
testcase_05 AC 2 ms
4,892 KB
testcase_06 AC 3 ms
4,600 KB
testcase_07 AC 3 ms
4,672 KB
testcase_08 AC 3 ms
4,744 KB
testcase_09 AC 3 ms
4,796 KB
testcase_10 AC 3 ms
4,564 KB
testcase_11 AC 3 ms
4,848 KB
testcase_12 AC 3 ms
4,712 KB
testcase_13 AC 3 ms
4,568 KB
testcase_14 AC 3 ms
4,884 KB
testcase_15 AC 3 ms
4,788 KB
testcase_16 AC 3 ms
4,784 KB
testcase_17 AC 3 ms
4,860 KB
testcase_18 AC 3 ms
4,588 KB
testcase_19 AC 180 ms
21,036 KB
testcase_20 AC 200 ms
21,144 KB
testcase_21 AC 3 ms
4,836 KB
testcase_22 AC 3 ms
4,508 KB
testcase_23 AC 3 ms
4,856 KB
testcase_24 AC 167 ms
79,500 KB
testcase_25 AC 169 ms
78,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

require "big"
n, m = read_line.split.map(&.to_i)
p = (0...n).to_a
m.times do
  s = read_line.split.map { |v| v.to_i - 1 }
  s.shift
  tmp = p[s[-1]]
  (s.size - 2).downto(0) do |i|
    p[s[i + 1]] = p[s[i]]
  end
  p[s[0]] = tmp
end
visited = Array.new(n, false)
ans = BigInt.new(1i64)
n.times do |i|
  next if visited[i]
  cur = i
  len = 0i64
  while !visited[cur]
    visited[cur] = true
    cur = p[cur]
    len += 1
  end
  ans = ans.lcm(len)
end
puts ans % 998244353
0