結果

問題 No.2428 Returning Shuffle
ユーザー tomeruntomerun
提出日時 2023-08-18 21:22:04
言語 Crystal
(1.11.2)
結果
AC  
実行時間 257 ms / 2,000 ms
コード長 473 bytes
コンパイル時間 15,034 ms
コンパイル使用メモリ 299,564 KB
実行使用メモリ 67,200 KB
最終ジャッジ日時 2024-05-06 03:10:20
合計ジャッジ時間 14,194 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
19,200 KB
testcase_01 AC 257 ms
19,200 KB
testcase_02 AC 249 ms
19,072 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 1 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 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 1 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 140 ms
19,072 KB
testcase_20 AC 141 ms
19,200 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 178 ms
67,200 KB
testcase_25 AC 162 ms
67,200 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