結果

問題 No.451 575
ユーザー femtofemto
提出日時 2016-12-03 00:41:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 856 bytes
コンパイル時間 1,513 ms
コンパイル使用メモリ 164,664 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-22 13:26:08
合計ジャッジ時間 5,210 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 4 ms
4,376 KB
testcase_07 AC 21 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 5 ms
4,380 KB
testcase_17 AC 21 ms
4,380 KB
testcase_18 AC 21 ms
4,380 KB
testcase_19 AC 13 ms
4,380 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 1 ms
4,380 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 4 ms
4,376 KB
testcase_30 AC 20 ms
4,392 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 6 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll MAX = 1e18;

ll a[100010];
ll b[100010];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

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

	ll min_a = 1, max_a = b[0] - 1;
	for(int i = 1; i < n; i++) {
		if(i % 2 == 0) {
			int min_a2 = b[i] - (max_a - 1);
			int max_a2 = b[i] - (min_a - 1);;
			min_a = min_a2;
			max_a = max_a2;
		} else {
			min_a -= b[i];
			max_a -= b[i];
		}
		min_a = max(1LL, min_a);
		max_a = min(MAX, max_a);
	}

	if(max_a <= 0 || min_a > MAX || max_a < min_a) {
		cout << -1 << endl;
		return 0;
	}

	cout << n + 1 << endl;
	a[n] = min_a;
	for(int i = n - 1; i >= 0; i--) {
		if(i % 2 == 0) {
			a[i] = b[i] - a[i + 1];
		} else {
			a[i] = b[i] + a[i + 1];
		}
	}

	for(int i = 0; i < n + 1; i++) {
		cout << a[i] << endl;
	}
}
0