結果

問題 No.482 あなたの名は
ユーザー もいちゃんもいちゃん
提出日時 2017-03-09 15:56:51
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 408 bytes
コンパイル時間 199 ms
コンパイル使用メモリ 11,256 KB
実行使用メモリ 28,032 KB
最終ジャッジ日時 2023-09-06 05:25:11
合計ジャッジ時間 6,421 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
15,052 KB
testcase_01 AC 79 ms
15,136 KB
testcase_02 AC 79 ms
15,308 KB
testcase_03 AC 80 ms
15,160 KB
testcase_04 AC 79 ms
15,136 KB
testcase_05 AC 78 ms
15,052 KB
testcase_06 AC 79 ms
15,276 KB
testcase_07 AC 79 ms
15,260 KB
testcase_08 AC 79 ms
15,156 KB
testcase_09 AC 77 ms
15,120 KB
testcase_10 AC 80 ms
15,108 KB
testcase_11 AC 77 ms
15,128 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 181 ms
27,760 KB
testcase_17 AC 182 ms
27,928 KB
testcase_18 AC 183 ms
27,840 KB
testcase_19 WA -
testcase_20 AC 182 ms
27,872 KB
testcase_21 AC 183 ms
27,768 KB
testcase_22 WA -
testcase_23 AC 178 ms
28,008 KB
testcase_24 WA -
testcase_25 AC 181 ms
27,812 KB
testcase_26 WA -
testcase_27 AC 183 ms
27,920 KB
testcase_28 AC 176 ms
27,960 KB
testcase_29 AC 174 ms
28,032 KB
testcase_30 AC 79 ms
15,108 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:1: warning: assigned but unused variable - n
Syntax OK

ソースコード

diff #

n, k = gets.split().map(&:to_i)
nums = gets.split().map(&:to_i)
a,b,score = 0,0,0
nums.each_with_index do |c,i|
  if i+1 == c
    next
  elsif i+1 == nums[c-1]
    a += 1
  elsif i+1 != nums[c-1]
    b += 1
  end
end

score += a / 2 if a > 1
score += b - 1 if b > 2

if score % 2 == 0 && k % 2 == 0 && score <= k
  puts "YES"
elsif score % 2 != 0 && k % 2 != 0 && score <= k
  puts "YES"
else
  puts "NO"
end
0