結果

問題 No.451 575
ユーザー tansunogontansunogon
提出日時 2017-01-07 05:17:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 200 ms / 2,000 ms
コード長 1,181 bytes
コンパイル時間 534 ms
コンパイル使用メモリ 67,008 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-22 15:39:12
合計ジャッジ時間 4,318 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 4 ms
4,376 KB
testcase_06 AC 9 ms
4,380 KB
testcase_07 AC 65 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 50 ms
4,376 KB
testcase_11 AC 151 ms
4,376 KB
testcase_12 AC 199 ms
4,380 KB
testcase_13 AC 198 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 11 ms
4,376 KB
testcase_17 AC 64 ms
4,380 KB
testcase_18 AC 64 ms
4,380 KB
testcase_19 AC 42 ms
4,380 KB
testcase_20 AC 9 ms
4,376 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 200 ms
4,376 KB
testcase_24 AC 103 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 8 ms
4,376 KB
testcase_30 AC 64 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 14 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

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()
{
	ll a_min;
	ll a_max;
	if (n % 2 == 1)
	{
		a_min = MIN_A;
		a_max = MAX_A - 1;
	}
	else
	{
		a_min = MIN_A;
		a_max = MAX_A- b[n];
	}

	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