結果

問題 No.913 木の燃やし方
ユーザー chocoruskchocorusk
提出日時 2019-10-19 00:41:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,628 bytes
コンパイル時間 1,591 ms
コンパイル使用メモリ 119,876 KB
実行使用メモリ 11,716 KB
最終ジャッジ日時 2023-09-08 03:22:14
合計ジャッジ時間 11,274 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,496 KB
testcase_01 AC 2 ms
5,536 KB
testcase_02 AC 2 ms
5,488 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 211 ms
10,748 KB
testcase_14 AC 198 ms
10,356 KB
testcase_15 AC 198 ms
10,392 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 175 ms
11,096 KB
testcase_20 AC 209 ms
10,852 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 140 ms
10,948 KB
testcase_25 AC 125 ms
10,984 KB
testcase_26 AC 219 ms
10,812 KB
testcase_27 AC 186 ms
11,700 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 161 ms
11,716 KB
testcase_32 AC 174 ms
11,708 KB
testcase_33 AC 180 ms
11,708 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 175 ms
10,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, ll> P;
typedef __int128_t lll;
int n;
ll a[200020];
ll s[200020];
ll ans[200020];
void solve(int l, int r){
	if(l>r) return;
	if(l==r){
		ans[l]=min(ans[l], 1+a[l]);
		return;
	}
	int m=(l+r)/2;
	deque<int> cht;
	for(int i=r; i>=m; i--){
		ll a0=-2*(i+1), b0=(ll)(i+1)*(i+1)+s[i+1];
		while(cht.size()>1){
            int i1=cht[cht.size()-1], i2=cht[cht.size()-2];
            ll a1=-2*i1, b1=(ll)i1*i1+s[i1];
            ll a2=-2*i2, b2=(ll)i2*i2+s[i2];
            if((lll)(b1-b2)*(a1-a0)<(lll)(b0-b1)*(a2-a1)) break;
            cht.pop_back();
        }
        cht.push_back(i+1);
	}
	vector<ll> vm1(m-l+1), vm2(r-m+1);
	for(int i=m; i>=l; i--){
		while(cht.size()>1){
            int i1=cht[0], i2=cht[1];
            ll a1=-2*i1, b1=(ll)i1*i1+s[i1];
            ll a2=-2*i2, b2=(ll)i2*i2+s[i2];
            if(a1*(ll)i+b1<a2*(ll)i+b2) break;
            cht.pop_front();
        }
		int r=cht[0];
		vm1[i-l]=(ll)(r-i)*(r-i)+s[r]-s[i];
	}
	ll mn=1e18;
	for(int i=l; i<=m; i++){
		mn=min(mn, vm1[i-l]);
		ans[i]=min(ans[i], mn);
	}

	cht.clear();
	for(int i=l; i<=m; i++){
		ll a0=-2*i, b0=(ll)i*i-s[i];
		while(cht.size()>1){
            int i1=cht[cht.size()-1], i2=cht[cht.size()-2];
            ll a1=-2*i1, b1=(ll)i1*i1-s[i1];
            ll a2=-2*i2, b2=(ll)i2*i2-s[i2];
            if((lll)(b1-b2)*(a1-a0)<(lll)(b0-b1)*(a2-a1)) break;
            cht.pop_back();
        }
        cht.push_back(i);
	}
	for(int i=m; i<=r; i++){
		while(cht.size()>1){
            int i1=cht[0], i2=cht[1];
            ll a1=-2*i1, b1=(ll)i1*i1-s[i1];
            ll a2=-2*i2, b2=(ll)i2*i2-s[i2];
            if(a1*(ll)(i+1)+b1<a2*(ll)(i+1)+b2) break;
            cht.pop_front();
        }
		int l=cht[0];
		vm2[i-m]=(ll)(i+1-l)*(i+1-l)+s[i+1]-s[l];
	}
	mn=1e18;
	for(int i=r; i>=m; i--){
		mn=min(mn, vm2[i-m]);
		ans[i]=min(ans[i], mn);
	}
	solve(l, m-1);
	solve(m+1, r);
}
int main()
{
	cin>>n;
	s[0]=0;
    for(int i=0; i<n; i++){
        cin>>a[i];
        s[i+1]=s[i]+a[i];
    }
	const ll INF=1e18;
	fill(ans, ans+n, INF);
	solve(0, n-1);
	for(int i=0; i<n; i++){
		printf("%lld\n", ans[i]);
	}
    return 0;
}
0