結果

問題 No.1965 Heavier
ユーザー simansiman
提出日時 2022-06-07 17:07:45
言語 Ruby
(3.3.0)
結果
AC  
実行時間 294 ms / 2,000 ms
コード長 333 bytes
コンパイル時間 433 ms
コンパイル使用メモリ 11,888 KB
実行使用メモリ 45,732 KB
最終ジャッジ日時 2023-10-21 03:50:39
合計ジャッジ時間 8,627 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
16,100 KB
testcase_01 AC 77 ms
16,100 KB
testcase_02 AC 74 ms
16,100 KB
testcase_03 AC 72 ms
16,100 KB
testcase_04 AC 71 ms
16,100 KB
testcase_05 AC 77 ms
16,100 KB
testcase_06 AC 293 ms
45,448 KB
testcase_07 AC 284 ms
45,440 KB
testcase_08 AC 277 ms
45,136 KB
testcase_09 AC 280 ms
45,564 KB
testcase_10 AC 276 ms
45,564 KB
testcase_11 AC 272 ms
45,564 KB
testcase_12 AC 71 ms
16,100 KB
testcase_13 AC 74 ms
16,100 KB
testcase_14 AC 71 ms
16,096 KB
testcase_15 AC 274 ms
45,368 KB
testcase_16 AC 277 ms
45,368 KB
testcase_17 AC 222 ms
41,416 KB
testcase_18 AC 284 ms
45,248 KB
testcase_19 AC 276 ms
44,924 KB
testcase_20 AC 286 ms
45,228 KB
testcase_21 AC 260 ms
44,320 KB
testcase_22 AC 266 ms
44,148 KB
testcase_23 AC 208 ms
39,096 KB
testcase_24 AC 236 ms
42,952 KB
testcase_25 AC 276 ms
45,172 KB
testcase_26 AC 280 ms
44,976 KB
testcase_27 AC 294 ms
45,732 KB
testcase_28 AC 290 ms
45,732 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
A = gets.split.map(&:to_i)
B = gets.split.map(&:to_i)

ans = 0
len = 0

(N - 1).times do |i|
  a1, b1 = A[i], B[i]
  a2, b2 = A[i + 1], B[i + 1]
  min_b, max_b = [b1, b2].minmax

  if a1 + max_b < a2 + min_b
    len += 1
  else
    ans += len * (1 + len) / 2
    len = 0
  end
end

ans += len * (1 + len) / 2

puts ans
0