結果

問題 No.451 575
ユーザー hotpepsihotpepsi
提出日時 2016-12-02 23:17:30
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 188 ms / 2,000 ms
コード長 1,032 bytes
コンパイル時間 526 ms
コンパイル使用メモリ 58,960 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-16 11:13:14
合計ジャッジ時間 3,908 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <cstdio>

using namespace std;
typedef long long LL;

int main(int argc, char *argv[]) {
	LL N, a[100001], b[100000], low = 1, high = 1000000000000000000;
	cin >> N;
	bool valid = true;
	for (int i = 0; i != N; ++i) {
		cin >> b[i];
		if (i % 2) {
			low = max(low, b[i] + 1);
			if (low > high) {
				valid = false;
			}
			LL next_low = max(1LL, low - b[i]);
			LL next_high = high - b[i];
			low = next_low;
			high = next_high;
			if (low > high) {
				valid = false;
			}
		} else {
			LL next_low = max(1LL, b[i] - high);
			LL next_high = b[i] - low;
			low = next_low;
			high = next_high;
			if (low > high) {
				valid = false;
			}
		}
	}
	if (!valid) {
		cout << -1 << endl;
	} else {
		a[N] = low;
		for (int i = N - 1; i >= 0; --i) {
			if (i % 2) {
				low += b[i];
			} else {
				low = b[i] - low;
			}
			a[i] = low;
		}
		cout << (N + 1) << endl;
		for (int i = 0; i <= N; ++i) {
			cout << a[i] << endl;
		}
	}
	return 0;
}
0