結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
19,548 KB
testcase_01 AC 80 ms
15,072 KB
testcase_02 AC 83 ms
15,164 KB
testcase_03 AC 79 ms
15,084 KB
testcase_04 AC 81 ms
15,340 KB
testcase_05 AC 79 ms
15,132 KB
testcase_06 AC 79 ms
15,076 KB
testcase_07 AC 81 ms
15,080 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 81 ms
15,320 KB
testcase_11 AC 82 ms
15,344 KB
testcase_12 AC 82 ms
15,120 KB
testcase_13 AC 84 ms
15,148 KB
testcase_14 AC 81 ms
15,252 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
  puts "YES"
elsif k.even? && cnt.even? || k.odd? && cnt.odd?
  puts "YES"
else
  puts "NO"
end
0