結果

問題 No.451 575
ユーザー tansunogon
提出日時 2017-01-07 04:57:48
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
RE  
実行時間 -
コード長 1,120 bytes
コンパイル時間 662 ms
コンパイル使用メモリ 69,048 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-12-17 15:15:23
合計ジャッジ時間 5,800 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 24 RE * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cassert>
using namespace std;

using ll = long long;
const ll INF = 1e18 + 100;

const int MAX_N = 1e5;
const ll MAX_A = 1e18;
const ll MIN_A = 1;
int n;
ll b[MAX_N + 1];

// return a_1
ll solve()
{
	if (n == 1 && b[1] == 1)
		return -1;
	ll a_min = -INF;
	ll a_max =  INF;
	for (int i = n; i >= 1; --i)
	{
		if (i % 2 == 1)
		{
			ll a_min_ = b[i] - a_max;
			ll a_max_ = b[i] - a_min;
			a_min = max(MIN_A, a_min_);
			a_max = min(MAX_A, a_max_);
		}
		else
		{
			a_min = max(MIN_A, b[i] + a_min);
			a_max = min(MAX_A, b[i] + a_max);
		}
		if (a_min > a_max)
			return -1;
	}
	return a_min;
}

void output(ll a_1)
{
	ll a = a_1;
	cout << n + 1 << endl;
	cout << a << endl;
	for (int i = 1; i <= n; ++i)
	{
		if (i % 2 == 1)
		{
			a = b[i] - a;
			assert(a >= MIN_A && a <= MAX_A);
			cout << a << endl;
		}
		else
		{
			a = a - b[i];
			assert(a >= MIN_A && a <= MAX_A);
			cout << a << endl;
		}
	}
}

int main()
{
	cin >> n;
	for (int i = 1; i <= n; ++i)
		cin >> b[i];

	ll a_1 = solve();
	if (a_1 != -1)
		output(a_1);
	else
		cout << -1 << endl;
	return 0;
}
0