結果

問題 No.451 575
ユーザー hotpepsihotpepsi
提出日時 2016-12-02 23:17:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 203 ms / 2,000 ms
コード長 1,032 bytes
コンパイル時間 470 ms
コンパイル使用メモリ 60,836 KB
実行使用メモリ 4,964 KB
最終ジャッジ日時 2023-08-22 13:45:03
合計ジャッジ時間 4,494 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

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