結果

問題 No.482 あなたの名は
ユーザー ryoo14ryoo14
提出日時 2017-02-11 10:22:58
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 358 bytes
コンパイル時間 54 ms
コンパイル使用メモリ 11,448 KB
実行使用メモリ 33,692 KB
最終ジャッジ日時 2023-08-28 12:46:39
合計ジャッジ時間 5,452 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
19,716 KB
testcase_01 AC 81 ms
15,084 KB
testcase_02 AC 83 ms
15,304 KB
testcase_03 AC 83 ms
15,220 KB
testcase_04 AC 81 ms
15,348 KB
testcase_05 AC 80 ms
15,156 KB
testcase_06 AC 81 ms
15,116 KB
testcase_07 AC 83 ms
15,168 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 81 ms
15,356 KB
testcase_11 AC 81 ms
15,132 KB
testcase_12 AC 80 ms
15,136 KB
testcase_13 AC 79 ms
15,108 KB
testcase_14 AC 81 ms
15,068 KB
testcase_15 TLE -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n,k = gets.split.map(&:to_i)
d = gets.split.map(&:to_i)
d = d.map { |v| v-1 }
cnt = 0

n.times do |i|
  if d[i] == i
    next
  else
    t = d.index(i)
    tm = d[t]
    d[t] = d[i]
    d[i] = tm
    cnt += 1
  end
end

if cnt == 0
  if k.even?
    puts "YES"
  else
    puts "NO"
  end
elsif cnt == k || (k - cnt) % 2 == 0
  puts "YES"
else
  puts "NO"
end
0