結果

問題 No.482 あなたの名は
ユーザー simansiman
提出日時 2020-11-16 02:55:12
言語 Ruby
(3.3.0)
結果
AC  
実行時間 326 ms / 2,000 ms
コード長 445 bytes
コンパイル時間 40 ms
コンパイル使用メモリ 11,404 KB
実行使用メモリ 46,296 KB
最終ジャッジ日時 2023-09-30 07:10:21
合計ジャッジ時間 8,150 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
15,112 KB
testcase_01 AC 67 ms
15,120 KB
testcase_02 AC 73 ms
15,132 KB
testcase_03 AC 73 ms
15,248 KB
testcase_04 AC 72 ms
15,052 KB
testcase_05 AC 72 ms
15,024 KB
testcase_06 AC 72 ms
15,100 KB
testcase_07 AC 75 ms
15,120 KB
testcase_08 AC 74 ms
15,052 KB
testcase_09 AC 71 ms
15,128 KB
testcase_10 AC 72 ms
15,036 KB
testcase_11 AC 72 ms
15,128 KB
testcase_12 AC 72 ms
15,052 KB
testcase_13 AC 72 ms
15,276 KB
testcase_14 AC 73 ms
15,212 KB
testcase_15 AC 318 ms
45,428 KB
testcase_16 AC 313 ms
45,696 KB
testcase_17 AC 306 ms
45,976 KB
testcase_18 AC 302 ms
45,880 KB
testcase_19 AC 306 ms
45,996 KB
testcase_20 AC 304 ms
45,744 KB
testcase_21 AC 310 ms
45,596 KB
testcase_22 AC 312 ms
45,668 KB
testcase_23 AC 319 ms
45,652 KB
testcase_24 AC 326 ms
45,664 KB
testcase_25 AC 321 ms
45,944 KB
testcase_26 AC 325 ms
45,484 KB
testcase_27 AC 308 ms
45,968 KB
testcase_28 AC 306 ms
45,472 KB
testcase_29 AC 297 ms
46,296 KB
testcase_30 AC 69 ms
15,016 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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
0