結果

問題 No.1375 Divide and Update
ユーザー yuruhiyayuruhiya
提出日時 2021-02-06 17:54:16
言語 Crystal
(1.11.2)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 553 bytes
コンパイル時間 21,170 ms
コンパイル使用メモリ 256,424 KB
実行使用メモリ 25,148 KB
最終ジャッジ日時 2023-09-16 03:58:57
合計ジャッジ時間 24,609 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,356 KB
testcase_01 AC 2 ms
4,340 KB
testcase_02 AC 2 ms
4,388 KB
testcase_03 AC 2 ms
4,464 KB
testcase_04 AC 2 ms
4,328 KB
testcase_05 AC 3 ms
4,408 KB
testcase_06 AC 2 ms
4,328 KB
testcase_07 AC 2 ms
4,456 KB
testcase_08 AC 3 ms
4,328 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 47 ms
25,148 KB
testcase_11 AC 43 ms
18,620 KB
testcase_12 AC 27 ms
15,856 KB
testcase_13 AC 22 ms
11,560 KB
testcase_14 AC 51 ms
24,900 KB
testcase_15 AC 52 ms
24,108 KB
testcase_16 AC 53 ms
24,768 KB
testcase_17 AC 53 ms
24,028 KB
testcase_18 AC 51 ms
23,716 KB
testcase_19 AC 51 ms
23,720 KB
testcase_20 AC 40 ms
20,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

lib C
  fun strtoll(s : UInt8*, p : UInt8**, b : Int32) : Int64
end

class String
  def to_i64
    C.strtoll(self, nil, 10)
  end
end

def generate_dp(n, a, x)
  dp = [-10i64 ** 9] * -~n
  n.times do |i|
    dp[i + 1] = (x - a[i]) + {dp[i], 0i64}.max
  end
  n.times do |i|
    dp[i + 1] = {dp[i + 1], dp[i]}.max
  end
  dp
end

n, x, y = read_line.split.map(&.to_i64)
a = read_line.split.map(&.to_i64)
sum = a.sum
left = generate_dp(n, a, x)
right = generate_dp(n, a.reverse, y).reverse
puts (1...n - 1).join('\n') { |i| sum + left[i] + right[i + 1] }
0