結果

問題 No.1375 Divide and Update
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2021-02-05 23:07:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 386 ms / 2,000 ms
コード長 1,043 bytes
コンパイル時間 2,825 ms
コンパイル使用メモリ 171,364 KB
実行使用メモリ 25,908 KB
最終ジャッジ日時 2023-09-15 10:41:51
合計ジャッジ時間 8,050 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,388 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 325 ms
23,032 KB
testcase_11 AC 300 ms
21,076 KB
testcase_12 AC 168 ms
12,760 KB
testcase_13 AC 136 ms
11,224 KB
testcase_14 AC 369 ms
25,596 KB
testcase_15 AC 372 ms
25,856 KB
testcase_16 AC 369 ms
25,608 KB
testcase_17 AC 376 ms
25,672 KB
testcase_18 AC 374 ms
25,560 KB
testcase_19 AC 386 ms
25,908 KB
testcase_20 AC 331 ms
25,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2021.02.05 23:07:33
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

int main() {
    int n,x,y; cin >> n >> x >> y;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    
    constexpr long long LLINF = 1e18 + 1;
    vector<vector<ll>> dpx(n+1,vector<ll>(3)),dpy(n+1,vector<ll>(3));
    dpx[0][1] = -LLINF;
    dpy[n][1] = -LLINF;
    dpx[0][2] = -LLINF;
    dpy[n][2] = -LLINF;
    for (int i = 0; i < n; i++) {
        dpx[i+1][0] = dpx[i][0]+a[i];
        dpx[i+1][1] = max(dpx[i][1]+x,dpx[i][0]+x);
        dpx[i+1][2] = max(dpx[i][1]+a[i],dpx[i][2]+a[i]);
    }
    for (int i = n-1; i >= 0; i--) {
        dpy[i][0] = dpy[i+1][0]+a[i];
        dpy[i][1] = max(dpy[i+1][1]+y,dpy[i+1][0]+y);
        dpy[i][2] = max(dpy[i+1][1]+a[i],dpy[i+1][2]+a[i]);
    }
    
    
    for (int i = 1; i < n-1; i++) {
        cout << max({dpx[i][1],dpx[i][2]}) + a[i] + max({dpy[i+1][1],dpy[i+1][2]}) << endl;
    }
    return 0;
}
0