結果

問題 No.1375 Divide and Update
ユーザー seiyuseiyu
提出日時 2021-02-08 01:57:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,010 bytes
コンパイル時間 2,380 ms
コンパイル使用メモリ 170,720 KB
実行使用メモリ 12,848 KB
最終ジャッジ日時 2023-09-18 04:22:46
合計ジャッジ時間 6,429 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 1 ms
4,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

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; }

__attribute__ ((constructor))
void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
}

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]; }
    // cout << "----------------------------" << endl;
    rep(i, n) { 
        sum_y[i + 1] = sum_y[i] + y - a_rev[i];
        // cout << sum_y[i + 1] << endl;
    }
    // cout << "----------------------------" << endl;

    ll min_x , max_x;
    ll min_y, max_y;

    // cout << "loop" << endl;

    rep(i,n){
        // cout << min_x << " " << max_x << endl;
        // cout << min_y << " " << max_y << endl;
        // cout << "-----------------------" << endl;
        if(i == 0){
            ans_x[i] = sum_x[i + 1];
            ans_y[i] = sum_y[i + 1];
            min_x = sum_x[i+1];
            max_x = sum_x[i+1];
            min_y = sum_y[i+1];
            max_y = sum_y[i+1];
        }else{
            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]);
            chmax(max_x, sum_x[i + 1]);
            chmax(max_y, sum_y[i + 1]);
        }
        // cout << i << endl;
        // cout << min_x << " " << max_x << " " << min_y << " " << max_y << endl;
        // cout << ans_x[i] << endl;
        // cout << ans_y[i] << endl;
    }

    // cout << "  loop end " << endl;

    // cout << " ans_y " << endl;
    // rep(i, n) cout << ans_y[i] << endl;
    // cout << "----------------" << endl;
    // cout << "-------------------" << endl;

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

    // cout << all_sum << endl;

    FOR(i,1,n-1){
        ll pre = all_sum;
        all_sum += ans_x[i - 1];
        // cout << ans_x[i-1] << endl;
        all_sum += ans_y[n - i - 2];
        // cout << ans_y[n-i-2] << endl;
        if(2 <= i && i != n-1) cout << all_sum + 1 << endl;
        else
            cout << all_sum << endl;
        // cout << "-------------------" << endl;

        all_sum = pre;
    }

    return 0;
}
0