結果

問題 No.1687 What the Heck?
ユーザー siman
提出日時 2021-09-26 04:23:05
言語 Ruby
(3.4.1)
結果
WA  
実行時間 -
コード長 271 bytes
コンパイル時間 413 ms
コンパイル使用メモリ 7,296 KB
実行使用メモリ 35,328 KB
最終ジャッジ日時 2024-07-05 15:34:32
合計ジャッジ時間 3,573 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 16 WA * 2
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:3: warning: assigned but unused variable - idx
Syntax OK

ソースコード

diff #

N = gets.to_i
P = gets.split.map(&:to_i)
idx = P.index(N) + 1
rounds = Hash.new

P.each.with_index(1) do |x, i|
  rounds[x] = i
end

i = N
sum = (1..N).sum

while i >= 2 && 2 * rounds[i - 1] <= rounds[i]
  sum -= rounds[i]
  i -= 1
end

puts [0, sum - 2 * rounds[i]].max
0