結果

問題 No.482 あなたの名は
ユーザー wotsushiwotsushi
提出日時 2017-03-29 21:05:32
言語 Ruby
(3.3.0)
結果
AC  
実行時間 191 ms / 2,000 ms
コード長 332 bytes
コンパイル時間 830 ms
コンパイル使用メモリ 11,376 KB
実行使用メモリ 29,596 KB
最終ジャッジ日時 2023-09-20 20:17:03
合計ジャッジ時間 6,352 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
15,164 KB
testcase_01 AC 78 ms
15,080 KB
testcase_02 AC 77 ms
15,248 KB
testcase_03 AC 77 ms
15,288 KB
testcase_04 AC 77 ms
15,224 KB
testcase_05 AC 78 ms
15,168 KB
testcase_06 AC 79 ms
15,124 KB
testcase_07 AC 77 ms
15,192 KB
testcase_08 AC 78 ms
15,168 KB
testcase_09 AC 78 ms
15,144 KB
testcase_10 AC 78 ms
15,168 KB
testcase_11 AC 78 ms
15,076 KB
testcase_12 AC 78 ms
15,156 KB
testcase_13 AC 77 ms
15,080 KB
testcase_14 AC 78 ms
15,084 KB
testcase_15 AC 188 ms
29,544 KB
testcase_16 AC 190 ms
29,596 KB
testcase_17 AC 184 ms
29,328 KB
testcase_18 AC 189 ms
29,384 KB
testcase_19 AC 191 ms
29,388 KB
testcase_20 AC 184 ms
29,500 KB
testcase_21 AC 185 ms
29,596 KB
testcase_22 AC 188 ms
29,328 KB
testcase_23 AC 187 ms
29,276 KB
testcase_24 AC 189 ms
29,536 KB
testcase_25 AC 186 ms
29,368 KB
testcase_26 AC 189 ms
29,480 KB
testcase_27 AC 185 ms
29,352 KB
testcase_28 AC 186 ms
29,332 KB
testcase_29 AC 181 ms
29,376 KB
testcase_30 AC 78 ms
15,088 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, K = gets.split.map(&:to_i)
D = gets.split.map(&:to_i)
u = Array.new(N + 1, false)
m = 0
for i in (1..N)
  j = i
  l = 0
  unless u[j]
    until u[j] do
      u[j] = true
      j = D[j - 1]
      l += 1
    end
    m += l - 1
  end
end
ans = if m <= K and (K - m) % 2 == 0
        "YES"
      else
        "NO"
      end
puts ans
0