結果

問題 No.8103 Range Chmax and Maximize Abs Sum
ユーザー SSRS
提出日時 2023-03-31 22:34:59
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 658 bytes
コンパイル時間 1,658 ms
コンパイル使用メモリ 172,480 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-23 01:22:59
合計ジャッジ時間 3,703 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 16 WA * 8
権限があれば一括ダウンロードができます

ソースコード

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