結果

問題 No.3103 Range Chmax and Maximize Abs Sum
ユーザー SSRSSSRS
提出日時 2023-03-31 22:15:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 681 bytes
コンパイル時間 1,840 ms
コンパイル使用メモリ 170,184 KB
実行使用メモリ 10,948 KB
最終ジャッジ日時 2023-10-24 08:19:06
合計ジャッジ時間 6,328 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,948 KB
testcase_01 RE -
testcase_02 AC 149 ms
4,348 KB
testcase_03 AC 3 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 RE -
testcase_09 WA -
testcase_10 WA -
testcase_11 RE -
testcase_12 AC 2 ms
4,348 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 TLE -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long INF = 100000000000;
int main(){
  int N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  vector<long long> dp(N + 1, 0);
  for (int i = 0; i < N; i++){
    int L = i, R = i;
    while (L > 0){
      if (A[L - 1] <= A[i]){
        L--;
      } else {
        break;
      }
    }
    while (R < N){
      if (A[R + 1] <= A[i]){
        R++;
      } else {
        break;
      }
    }
    for (int j = L; j <= i; j++){
      for (int k = i + 1; k <= R + 1; k++){
        dp[k] = max(dp[k], dp[j] + (long long) (k - j) * abs(A[i]));
      }
    }
  }
  cout << dp[N] << endl;
}
0