結果

問題 No.1375 Divide and Update
ユーザー seiyu_kyoproseiyu_kyopro
提出日時 2021-02-08 02:29:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 350 ms / 2,000 ms
コード長 1,837 bytes
コンパイル時間 1,633 ms
コンパイル使用メモリ 170,300 KB
実行使用メモリ 12,268 KB
最終ジャッジ日時 2023-09-18 05:06:47
合計ジャッジ時間 7,297 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 304 ms
11,208 KB
testcase_11 AC 278 ms
10,484 KB
testcase_12 AC 151 ms
7,536 KB
testcase_13 AC 126 ms
6,724 KB
testcase_14 AC 343 ms
12,212 KB
testcase_15 AC 345 ms
12,260 KB
testcase_16 AC 344 ms
12,220 KB
testcase_17 AC 340 ms
12,220 KB
testcase_18 AC 350 ms
12,260 KB
testcase_19 AC 350 ms
12,268 KB
testcase_20 AC 290 ms
12,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define rrep(i, n) for (int i = (int)n-1; i >= 0; --i)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    int n;
    ll x, y;
    cin >> n >> x >> y;

    vector<ll> a(n);
    vector<ll> a_rev;
    vector<ll> sum_x(n + 1, 0);
    vector<ll> sum_y(n + 1, 0);
    vector<ll> ans_x(n);
    vector<ll> ans_y(n);

    rep(i, n) cin >> a[i];

    reverse(a.begin(), a.end());

    a_rev = a;

    reverse(a.begin(), a.end());


    rep(i, n) { sum_x[i + 1] = sum_x[i] + x - a[i]; }
    rep(i, n) { 
        sum_y[i + 1] = sum_y[i] + y - a_rev[i];
    }

    ll min_x = 0, max_x;
    ll min_y = 0, max_y;

    rep(i,n){
        if(i == 0){
            ans_x[i] = sum_x[i + 1];
            ans_y[i] = sum_y[i + 1];
            chmin(min_x, sum_x[i + 1]);
            chmin(min_y, sum_y[i + 1]);
        }else{
            max_x = sum_x[i+1];
            max_y = sum_y[i+1];
            ans_x[i] = ans_x[i - 1];
            ans_y[i] = ans_y[i - 1];
            chmax(ans_x[i],sum_x[i + 1] - min_x);
            chmax(ans_y[i],sum_y[i + 1] - min_y);
            chmin(min_x, sum_x[i + 1]);
            chmin(min_y, sum_y[i + 1]);
        }
    }


    ll all_sum = accumulate(a.begin(), a.end(), 0ll);

    FOR(i,1,n-1){
        ll pre = all_sum;
        all_sum += ans_x[i - 1];
        all_sum += ans_y[n - i - 2];
        cout << all_sum << endl;

        all_sum = pre;
    }

    return 0;
}
0