結果

問題 No.3103 Range Chmax and Maximize Abs Sum
ユーザー SSRSSSRS
提出日時 2023-03-31 22:34:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 658 bytes
コンパイル時間 1,607 ms
コンパイル使用メモリ 172,436 KB
実行使用メモリ 5,712 KB
最終ジャッジ日時 2023-10-24 08:44:32
合計ジャッジ時間 3,770 ms
ジャッジサーバーID
(参考情報)
judge15 / 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 WA -
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 99 ms
5,712 KB
testcase_19 AC 99 ms
5,712 KB
testcase_20 AC 97 ms
5,712 KB
testcase_21 AC 97 ms
5,712 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 98 ms
5,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  vector<long long> dp(N + 1, 0);
  auto dfs = [&](auto dfs, int L, int R) -> void {
    if (L == R){
      return;
    }
    int p = L;
    int mx = A[L];
    for (int i = L + 1; i < R; i++){
      mx = max(mx, A[i]);
      if (A[i] < A[p]){
        p = i;
      }
    }
    dp[R] = max(dp[R], dp[L] + (long long) abs(mx) * (R - L));
    dfs(dfs, L, p);
    dp[p + 1] = max(dp[p + 1], dp[p] + abs(A[p]));
    dfs(dfs, p + 1, R);
  };
  dfs(dfs, 0, N);
  cout << dp[N] << endl;
}
0