結果

問題 No.482 あなたの名は
ユーザー ryoo14
提出日時 2017-02-11 10:38:06
言語 Ruby
(3.4.1)
結果
WA  
実行時間 -
コード長 289 bytes
コンパイル時間 133 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 27,008 KB
最終ジャッジ日時 2024-12-29 12:05:14
合計ジャッジ時間 6,399 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17 WA * 11
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:1: warning: assigned but unused variable - n
Syntax OK

ソースコード

diff #

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

d.each_with_index do |v,i|
  if v == i
    next
  else
    d[v] = v
    d[i] = i
    cnt += 1
  end
end

a = k - cnt
if a < 0 
  puts "NO"
elsif cnt == k || a % 2 == 0
  puts "YES"
else
  puts "NO"
end
0