結果

問題 No.913 木の燃やし方
ユーザー treeonetreeone
提出日時 2019-10-18 20:16:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,053 bytes
コンパイル時間 3,018 ms
コンパイル使用メモリ 200,452 KB
実行使用メモリ 12,332 KB
最終ジャッジ日時 2023-09-07 21:01:26
合計ジャッジ時間 9,201 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,768 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 13 ms
4,380 KB
testcase_04 AC 14 ms
4,380 KB
testcase_05 AC 15 ms
4,384 KB
testcase_06 AC 9 ms
4,380 KB
testcase_07 AC 4 ms
4,384 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
const int64 INF = 1e18;

struct CumulativeSum{
    vector<int64> data;
    CumulativeSum(int sz) : data(sz, 0) {};
    void add(int k, int64 x){
        data[k] += x;
    }
    void build(){
        for(int i = 1; i < data.size(); i++){
            data[i] += data[i - 1];
        }
    }
    int64 query(int k){
        if(k < 0) return 0;
        return (data[min(k, (int)data.size() - 1)]);
    }
    int64 query(int l, int r){
        return query(r - 1) - query(l - 1);
    }
};

int main(){
    int N;
	cin >> N;
    vector<int64> A(N), ans(N, INF);
    CumulativeSum S(N);
	for(int i = 0; i < N; i++){
        cin >> A[i];
        S.add(i, A[i]);
    }
    S.build();
    for(int l = 0; l < N; l++){
        int64 MIN = INF;
        for(int r = N; r > l; r--){
            int64 tmp = (r - l) * (r - l) + S.query(l, r);
            MIN = min(MIN, tmp);
            ans[r - 1] = min(ans[r - 1], MIN);
        }
    }
	for(int i = 0; i < N; i++){
		cout << ans[i] << endl;
	}
}
0