結果
| 問題 |
No.482 あなたの名は
|
| コンテスト | |
| ユーザー |
siman
|
| 提出日時 | 2020-11-16 02:55:12 |
| 言語 | Ruby (3.4.1) |
| 結果 |
AC
|
| 実行時間 | 415 ms / 2,000 ms |
| コード長 | 445 bytes |
| コンパイル時間 | 260 ms |
| コンパイル使用メモリ | 7,552 KB |
| 実行使用メモリ | 43,992 KB |
| 最終ジャッジ日時 | 2024-07-23 01:25:24 |
| 合計ジャッジ時間 | 9,723 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 |
コンパイルメッセージ
Syntax OK
ソースコード
N, K = gets.split.map(&:to_i)
D = gets.split.map(&:to_i)
E = Hash.new
D.each.with_index(1) do |d, idx|
E[idx] = d
end
visited = Hash.new(false)
cnt = 0
(1..N).each do |n|
next if visited[n]
cnt += 1
queue = []
queue << n
until queue.empty?
v = queue.shift
next if visited[v]
visited[v] = true
queue << E[v]
end
end
remain = K - (N - cnt)
if remain >= 0 && remain % 2 == 0
puts 'YES'
else
puts 'NO'
end
siman