結果

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

ソースコード

diff #

N = gets.to_i
P = gets.split.map(&:to_i)
rounds = Hash.new

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

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

while i >= 1
  score = sum - 2 * rounds[i]
  ans = score if ans < score
  sum -= rounds[i]
  i -= 1
end

puts ans
0