結果

問題 No.913 木の燃やし方
ユーザー 👑 kmjpkmjp
提出日時 2019-10-19 02:12:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,225 bytes
コンパイル時間 1,760 ms
コンパイル使用メモリ 173,064 KB
実行使用メモリ 11,084 KB
最終ジャッジ日時 2023-09-08 07:50:43
合計ジャッジ時間 19,984 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,644 KB
testcase_01 AC 2 ms
5,448 KB
testcase_02 AC 2 ms
5,444 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 8 ms
5,492 KB
testcase_06 AC 6 ms
5,528 KB
testcase_07 AC 3 ms
5,460 KB
testcase_08 AC 418 ms
9,548 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 420 ms
9,464 KB
testcase_12 AC 453 ms
9,736 KB
testcase_13 AC 434 ms
9,480 KB
testcase_14 AC 420 ms
9,388 KB
testcase_15 AC 409 ms
9,304 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 597 ms
11,084 KB
testcase_20 AC 432 ms
9,652 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 607 ms
11,080 KB
testcase_26 AC 450 ms
9,652 KB
testcase_27 AC 629 ms
11,072 KB
testcase_28 AC 423 ms
9,920 KB
testcase_29 AC 434 ms
9,616 KB
testcase_30 AC 454 ms
9,744 KB
testcase_31 AC 474 ms
10,832 KB
testcase_32 AC 477 ms
10,864 KB
testcase_33 AC 488 ms
11,004 KB
testcase_34 AC 483 ms
9,652 KB
testcase_35 AC 483 ms
9,696 KB
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


int N;
ll A[202020];
ll S[202020];
ll ret[202020];
ll cand[202020];

template<typename V> struct ConvexHull {
	deque<pair<V,V>> Q;
	V calc(pair<V,V> p, V x) {
		return p.first*x+p.second;
	}
	int dodo(pair<V,V> A,pair<V,V> B, pair<V,V> C) { // max or min
		return ((C.second-A.second)*(A.first-B.first)<=(B.second-A.second)*(A.first-C.first));
	}
	void add(V a, V b) { // add ax+b
		Q.push_back({a,b});
		int v;
		while((v=Q.size())>=3 && dodo(Q[v-3],Q[v-2],Q[v-1]))
			Q[v-2]=Q[v-1], Q.pop_back();
	}
	V query(V x) {
		int L=-1,R=Q.size()-1;
		while(R-L>1) {
			int M=(L+R)/2;
			(((calc(Q[M],x)>=calc(Q[M+1],x)))?L:R)=M;
		}
		return calc(Q[R],x);
	}
};

void dfs(int L,int R) {
	if(R-L<=2) {
		if(R-L==2) {
			ret[L]=min(ret[L],4+A[L]+A[R]);
			ret[R]=min(ret[R],4+A[L]+A[R]);
		}
		return;
	}
	int M=(L+R)/2;
	dfs(L,M);
	dfs(M+1,R);
	int i;
	ConvexHull<ll> ch;
	for(i=L;i<=M;i++) cand[i]=1LL<<60;
	for(i=M+1;i<=R;i++) {
		ch.add(-2*i,1LL*i*i+S[i]);
	}
	for(i=M;i>=L;i--) {
		cand[i]=1LL*i*i-S[i]+ch.query(i);
	}
	for(i=L;i<=M;i++) {
		cand[i+1]=min(cand[i+1],cand[i]);
		ret[i]=min(ret[i],cand[i]);
	}
	ch.Q.clear();
	for(i=M;i<=R;i++) cand[i]=1LL<<60;
	for(i=L;i<=M;i++) {
		ch.add(-2*i,1LL*i*i-S[i]);
	}
	for(i=M;i<R;i++) {
		cand[i]=1LL*(i+1)*(i+1)+S[i+1]+ch.query(i+1);
	}
	for(i=R-1;i>=M;i--) {
		cand[i-1]=min(cand[i],cand[i-1]);
		ret[i]=min(ret[i],cand[i]);
	}
	
	
	
	
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>A[i];
		S[i+1]=S[i]+A[i];
		ret[i]=1+A[i];
	}
	
	dfs(0,N);
	FOR(i,N) cout<<ret[i]<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0