結果

問題 No.2428 Returning Shuffle
ユーザー tomeruntomerun
提出日時 2023-08-18 21:19:34
言語 Crystal
(1.11.2)
結果
RE  
実行時間 -
コード長 432 bytes
コンパイル時間 23,859 ms
コンパイル使用メモリ 254,436 KB
実行使用メモリ 78,948 KB
最終ジャッジ日時 2023-08-18 21:20:21
合計ジャッジ時間 21,893 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 AC 3 ms
4,504 KB
testcase_04 AC 2 ms
4,468 KB
testcase_05 AC 3 ms
4,416 KB
testcase_06 AC 2 ms
4,500 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 2 ms
4,464 KB
testcase_09 AC 2 ms
4,356 KB
testcase_10 AC 3 ms
4,412 KB
testcase_11 AC 3 ms
4,484 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 3 ms
4,464 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 3 ms
4,428 KB
testcase_16 AC 2 ms
4,480 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 3 ms
4,472 KB
testcase_19 RE -
testcase_20 RE -
testcase_21 AC 3 ms
4,356 KB
testcase_22 AC 2 ms
4,356 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 152 ms
78,948 KB
testcase_25 AC 176 ms
78,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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 = 1i64
n.times do |i|
  next if visited[i]
  cur = i
  len = 0
  while !visited[cur]
    visited[cur] = true
    cur = p[cur]
    len += 1
  end
  ans = ans.lcm(len)
end
puts ans
0