結果

問題 No.482 あなたの名は
ユーザー cympfhcympfh
提出日時 2017-06-01 23:33:00
言語 Ruby
(3.2.2)
結果
AC  
実行時間 209 ms / 2,000 ms
コード長 316 bytes
コンパイル時間 58 ms
コンパイル使用メモリ 11,916 KB
実行使用メモリ 31,592 KB
最終ジャッジ日時 2023-10-21 20:18:33
合計ジャッジ時間 5,878 ms
ジャッジサーバーID
(参考情報)
judge15 / judge9
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
17,680 KB
testcase_01 AC 83 ms
17,680 KB
testcase_02 AC 82 ms
17,680 KB
testcase_03 AC 85 ms
17,680 KB
testcase_04 AC 83 ms
17,680 KB
testcase_05 AC 78 ms
17,680 KB
testcase_06 AC 79 ms
17,680 KB
testcase_07 AC 84 ms
17,680 KB
testcase_08 AC 84 ms
17,680 KB
testcase_09 AC 86 ms
17,680 KB
testcase_10 AC 81 ms
17,680 KB
testcase_11 AC 83 ms
17,680 KB
testcase_12 AC 83 ms
17,680 KB
testcase_13 AC 83 ms
17,680 KB
testcase_14 AC 85 ms
17,680 KB
testcase_15 AC 206 ms
31,592 KB
testcase_16 AC 205 ms
31,592 KB
testcase_17 AC 203 ms
31,592 KB
testcase_18 AC 201 ms
31,592 KB
testcase_19 AC 200 ms
31,592 KB
testcase_20 AC 198 ms
31,592 KB
testcase_21 AC 201 ms
31,592 KB
testcase_22 AC 195 ms
31,592 KB
testcase_23 AC 203 ms
31,592 KB
testcase_24 AC 203 ms
31,592 KB
testcase_25 AC 203 ms
31,592 KB
testcase_26 AC 201 ms
31,592 KB
testcase_27 AC 203 ms
31,592 KB
testcase_28 AC 209 ms
31,592 KB
testcase_29 AC 197 ms
31,592 KB
testcase_30 AC 79 ms
17,680 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n, m = gets.chomp.split.map(&:to_i)
ds = gets.chomp.split.map { |d| d.to_i - 1 }
dict = [nil] * 200_000
ds.each_with_index do |d, i|
  dict[d] = i
end
n.times do |i|
  next if dict[i] == i
  j = dict[i]
  k = ds[i]
  ds[i] = i
  ds[j] = k
  dict[k] = j
  dict[i] = i
  m -= 1
end
puts m >= 0 && m.even? ? :YES : :NO
0