結果

問題 No.2036 Max Middle
ユーザー tomeruntomerun
提出日時 2022-08-12 21:55:58
言語 Crystal
(1.11.2)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 282 bytes
コンパイル時間 14,257 ms
コンパイル使用メモリ 292,816 KB
実行使用メモリ 19,408 KB
最終ジャッジ日時 2023-10-24 09:51:08
合計ジャッジ時間 15,839 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 19 ms
11,784 KB
testcase_09 AC 29 ms
15,776 KB
testcase_10 AC 30 ms
15,800 KB
testcase_11 AC 26 ms
16,284 KB
testcase_12 AC 25 ms
16,284 KB
testcase_13 AC 32 ms
16,284 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 30 ms
19,408 KB
testcase_17 AC 21 ms
12,036 KB
testcase_18 AC 26 ms
16,272 KB
testcase_19 AC 25 ms
15,804 KB
testcase_20 AC 27 ms
16,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = read_line.to_i
a = read_line.split.map(&.to_i)
last = 0i64
1.upto(n - 1) do |i|
  last += a[i - 1] < a[i] ? 1 : -1
end
ans = 0i64
cur = 0i64
1.upto(n - 1) do |i|
  cur += a[i - 1] < a[i] ? 1 : -1
  bottom = {-i, last - (n - 1 - i)}.max
  ans += (cur - bottom) // 2
end
puts ans
0