結果

問題 No.482 あなたの名は
ユーザー finefine
提出日時 2017-02-10 22:37:20
言語 Ruby
(3.2.2)
結果
AC  
実行時間 207 ms / 2,000 ms
コード長 298 bytes
コンパイル時間 64 ms
コンパイル使用メモリ 11,516 KB
実行使用メモリ 29,560 KB
最終ジャッジ日時 2023-08-28 15:44:14
合計ジャッジ時間 6,230 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
15,120 KB
testcase_01 AC 84 ms
15,272 KB
testcase_02 AC 78 ms
15,220 KB
testcase_03 AC 82 ms
15,120 KB
testcase_04 AC 79 ms
15,300 KB
testcase_05 AC 77 ms
15,128 KB
testcase_06 AC 78 ms
15,164 KB
testcase_07 AC 79 ms
15,140 KB
testcase_08 AC 79 ms
15,208 KB
testcase_09 AC 80 ms
15,036 KB
testcase_10 AC 81 ms
15,108 KB
testcase_11 AC 79 ms
15,072 KB
testcase_12 AC 77 ms
15,164 KB
testcase_13 AC 79 ms
15,028 KB
testcase_14 AC 79 ms
15,160 KB
testcase_15 AC 194 ms
29,480 KB
testcase_16 AC 194 ms
29,408 KB
testcase_17 AC 198 ms
29,476 KB
testcase_18 AC 193 ms
29,532 KB
testcase_19 AC 190 ms
29,392 KB
testcase_20 AC 207 ms
29,356 KB
testcase_21 AC 196 ms
29,560 KB
testcase_22 AC 191 ms
29,384 KB
testcase_23 AC 197 ms
29,284 KB
testcase_24 AC 197 ms
29,472 KB
testcase_25 AC 195 ms
29,460 KB
testcase_26 AC 197 ms
29,336 KB
testcase_27 AC 199 ms
29,396 KB
testcase_28 AC 199 ms
29,328 KB
testcase_29 AC 192 ms
29,464 KB
testcase_30 AC 79 ms
15,304 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n, k = gets.split.map(&:to_i)
a = gets.split.map{|x|x.to_i - 1}
idx = Array.new(n)
n.times do |i|
    idx[a[i]] = i
end

cnt = 0
n.times do |i|
    next if a[i] == i
    idx[a[i]] = idx[i]
    a[idx[i]] = a[i]
    cnt += 1
end

if cnt > k || (k - cnt) % 2 == 1
    puts "NO"
else
    puts "YES"
end
0