結果

問題 No.451 575
ユーザー 🐬hec🐬hec
提出日時 2017-01-05 17:08:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 200 ms / 2,000 ms
コード長 1,306 bytes
コンパイル時間 1,524 ms
コンパイル使用メモリ 168,196 KB
実行使用メモリ 5,108 KB
最終ジャッジ日時 2023-08-22 14:40:15
合計ジャッジ時間 6,088 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

using namespace std;
using ll=long long;

// Problem Specific Parameter:

const ll inf=1LL<<60;
ll b[100000];

int main(void){
	int n;
	cin >> n;

	assert(1<=n and n<=100000);

	rep(i,n){
		cin >> b[i];
		assert(1LL<=b[i] and b[i]<=1000000000000000000LL);
	}


	ll cmin=1LL,cmax=inf;
	rep(i,n){
		if(i%2==0){
			// [a,b]+[K-b,K-a]=K
			ll ncmin=max(b[i]-cmax,1LL),ncmax=b[i]-cmin;
			cmin=ncmin,cmax=ncmax;

		}else{
			// [a,b]-[a-K,b-K]=K
			ll ncmin=max(cmin-b[i],1LL),ncmax=cmax-b[i];
			cmin=ncmin,cmax=ncmax;
		}

		if(cmin>cmax) break;	
	}

	if(cmin<=cmax){
		ll cur=cmin;
		vector<ll> ans={cur};

		rrep(i,n){
			if(i%2==0){
				cur=b[i]-cur;
			}else{
				cur=cur+b[i];
			}
			ans.push_back(cur);
		}

		reverse(begin(ans),end(ans));

		assert(int(ans.size())==n+1);
		cout << int(ans.size()) << endl;

		for(auto &it:ans){
			assert(it>0);
			cout << it << endl;
		}

	}else{
		cout << -1 << endl;
	}

	return 0;
}
0