結果

問題 No.1375 Divide and Update
ユーザー ShibuyapShibuyap
提出日時 2021-02-06 03:07:30
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 346 ms / 2,000 ms
コード長 958 bytes
コンパイル時間 2,200 ms
コンパイル使用メモリ 199,376 KB
実行使用メモリ 11,416 KB
最終ジャッジ日時 2023-09-15 11:10:05
合計ジャッジ時間 7,717 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 299 ms
10,356 KB
testcase_11 AC 273 ms
9,668 KB
testcase_12 AC 149 ms
6,748 KB
testcase_13 AC 124 ms
6,300 KB
testcase_14 AC 341 ms
11,416 KB
testcase_15 AC 338 ms
11,220 KB
testcase_16 AC 343 ms
11,192 KB
testcase_17 AC 342 ms
11,156 KB
testcase_18 AC 346 ms
11,168 KB
testcase_19 AC 343 ms
11,192 KB
testcase_20 AC 294 ms
11,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("YES");}else{puts("NO");}
#define MAX_N 200005

int main() {
    ll n, x, y;
    cin >> n >> x >> y;
    ll a[n] = {};
    rep(i,n) cin >> a[i];
    ll dp[n][2];
    dp[0][0] = x - a[0];
    dp[0][1] = x - a[0];
    srep(i,1,n){
        dp[i][1] = max(x-a[i], dp[i-1][1]+x-a[i]);
        dp[i][0] = max(dp[i-1][0], dp[i][1]);
    }
    ll dp2[n][2];
    dp2[n-1][0] = y - a[n-1];
    dp2[n-1][1] = y - a[n-1];
    drep(i,n-1){
        dp2[i][1] = max(y-a[i], dp2[i+1][1]+y-a[i]);
        dp2[i][0] = max(dp2[i+1][0], dp2[i][1]);
    }
    ll sum = 0;
    rep(i,n) sum += a[i];
    srep(i,1,n-1){
        ll ans = sum + dp[i-1][0] + dp2[i+1][0];
        cout << ans << endl;
    }
    return 0;
}
 
 
0