結果

問題 No.913 木の燃やし方
ユーザー square1001square1001
提出日時 2019-10-18 22:57:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,770 bytes
コンパイル時間 1,256 ms
コンパイル使用メモリ 97,084 KB
実行使用メモリ 43,144 KB
最終ジャッジ日時 2023-09-08 01:26:36
合計ジャッジ時間 11,602 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 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 139 ms
30,560 KB
testcase_14 AC 126 ms
28,732 KB
testcase_15 AC 131 ms
28,468 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 204 ms
42,300 KB
testcase_20 AC 441 ms
41,816 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 296 ms
42,108 KB
testcase_25 AC 185 ms
42,000 KB
testcase_26 AC 142 ms
30,440 KB
testcase_27 AC 140 ms
32,504 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <set>
#include <deque>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<long long> A(N + 1);
	for (int i = 0; i < N; ++i) {
		cin >> A[i + 1];
		A[i + 1] += A[i];
	}
	// minimize (A[i] - A[j]) + (i - j)^2 = (A[i] + i * i) + (-A[j] + j * j) - 2 * j * i for each i
	vector<long long> intercept(N + 1), slope(N + 1);
	for (int i = 0; i <= N; ++i) {
		intercept[i] = -A[i] + 1LL * i * i;
		slope[i] = -2 * i;
	}
	vector<int> seq(N + 1);
	deque<int> que;
	for (int i = 0; i <= N; ++i) {
		if (i >= 1) {
			seq[i] = que[0];
		}
		while (que.size() >= 2) {
			int pa = que[que.size() - 2];
			int pb = que[que.size() - 1];
			double cra = -double(intercept[pa] - intercept[i]) / (slope[pa] - slope[i]);
			double crb = -double(intercept[pb] - intercept[i]) / (slope[pb] - slope[i]);
			if (cra > crb) que.pop_back();
			else break;
		}
		que.push_back(i);
		while (que.size() >= 2) {
			int pa = que[0];
			int pb = que[1];
			long long va = 1LL * slope[pa] * (i + 1) + intercept[pa];
			long long vb = 1LL * slope[pb] * (i + 1) + intercept[pb];
			if (va > vb) que.pop_front();
			else break;
		}
	}
	vector<vector<long long> > qs;
	for (int i = 1; i <= N; ++i) {
		for (int j = seq[i - 1]; j <= seq[i]; ++j) {
			qs.push_back({ A[i] - A[j] + 1LL * (i - j) * (i - j), j, i });
		}
	}
	sort(qs.begin(), qs.end());
	set<int> st;
	for (int i = 0; i < N; ++i) {
		st.insert(i);
	}
	vector<long long> ans(N);
	for (vector<long long> i : qs) {
		set<int>::iterator it = st.lower_bound(i[1]);
		while (it != st.end() && *it < i[2]) {
			ans[*it] = i[0];
			it = st.erase(it);
		}
	}
	for (int i = 0; i < N; ++i) {
		cout << ans[i] << '\n';
	}
	return 0;
}
0