結果

問題 No.451 575
ユーザー finefine
提出日時 2016-12-03 00:55:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 155 ms / 2,000 ms
コード長 1,678 bytes
コンパイル時間 1,530 ms
コンパイル使用メモリ 167,216 KB
実行使用メモリ 4,692 KB
最終ジャッジ日時 2023-08-22 13:46:21
合計ジャッジ時間 5,111 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 5 ms
4,380 KB
testcase_07 AC 22 ms
4,692 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 40 ms
4,380 KB
testcase_11 AC 117 ms
4,412 KB
testcase_12 AC 153 ms
4,688 KB
testcase_13 AC 155 ms
4,688 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 5 ms
4,376 KB
testcase_17 AC 22 ms
4,652 KB
testcase_18 AC 22 ms
4,624 KB
testcase_19 AC 15 ms
4,376 KB
testcase_20 AC 7 ms
4,376 KB
testcase_21 AC 4 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 153 ms
4,608 KB
testcase_24 AC 86 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 4 ms
4,380 KB
testcase_30 AC 22 ms
4,576 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 7 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll INF = 1000000000000000001;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<ll> b(n);
	for (int i = 0; i < n; i++) cin >> b[i];
	bool flag = true;
	for (int i = 1; i < n; i++) {
		if (flag) {
			b[i] = b[i - 1] - b[i];			
		} else {
			b[i] += b[i - 1];
		}
		flag = (i / 2 % 2 == 0);
	} 

	ll min1 = INF, min2 = INF;
	int imin1 = -1, imin2 = -1;
	for (int i = 0; i < n; i++) {
		if (i / 2 % 2 == 0) {
			if (min1 > b[i]) {
				min1 = b[i];
				imin1 = i + 1;
			}
		} else {
			if (min2 > b[i]) {
				min2 = b[i];
				imin2 = i + 1;
			}
		}
	}
    if (imin1 != -1) {
	vector<ll> a1(n + 1);
	a1[imin1] = 1;
	a1[0] = b[imin1 - 1] - a1[imin1]; 
	flag = true;
    if (a1[0] <= 0 || a1[0] >= INF) flag = false;
	for (int i = 0; i < n; i++) {
		if (i / 2 % 2 == 0) {
			a1[i + 1] = b[i] - a1[0];
		} else {
			a1[i + 1] = -b[i] + a1[0];
		}
		if (a1[i + 1] <= 0 || a1[i + 1] >= INF) {
			flag = false;
			break;
		}
	}
	if (flag) {
		cout << n + 1 << endl;
		for (int i = 0; i <= n; i++) {
			cout << a1[i] << endl;
		}
		return 0;
	}
    }
    if (imin2 != -1) {
	vector<ll> a2(n + 1);
	a2[imin2] = 1;
	a2[0] = -b[imin2 - 1] + a2[imin2]; 
	flag = true;
    if (a2[0] <= 0 || a2[0] >= INF) flag = false;
	for (int i = 0; i < n; i++) {
		if (i / 2 % 2 == 0) {
			a2[i + 1] = b[i] - a2[0];
		} else {
			a2[i + 1] = -b[i] + a2[0];
		}
		if (a2[i + 1] <= 0 || a2[i + 1] >= INF) {
			flag = false;
			break;
		}
	}
	if (flag) {
		cout << n + 1 << endl;
		for (int i = 0; i <= n; i++) {
			cout << a2[i] << endl;
		}
		return 0;
	}
    }
	cout << -1 << endl;
	return 0;
}
0