結果

問題 No.451 575
ユーザー chaemonchaemon
提出日時 2016-12-02 00:47:53
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 201 ms / 2,000 ms
コード長 2,009 bytes
コンパイル時間 545 ms
コンパイル使用メモリ 75,996 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-22 12:41:47
合計ジャッジ時間 4,433 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 4 ms
4,376 KB
testcase_06 AC 10 ms
4,380 KB
testcase_07 AC 64 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 50 ms
4,380 KB
testcase_11 AC 150 ms
4,380 KB
testcase_12 AC 201 ms
4,380 KB
testcase_13 AC 199 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 11 ms
4,380 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,380 KB
testcase_21 AC 4 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 199 ms
4,380 KB
testcase_24 AC 104 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 8 ms
4,380 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
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:94:6: warning: ‘a’ may be used uninitialized in this function [-Wmaybe-uninitialized]
    a = b[i] - a;
    ~~^~~~~~~~~~
main.cpp:75:9: warning: ‘r’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   Int l,r;
         ^
main.cpp:75:7: warning: ‘l’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   Int l,r;
       ^

ソースコード

diff #

// #includes {{{
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <cmath>
using namespace std;
// }}}
// pre-written code {{{
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair

#define EXIST(e,s) ((s).find(e)!=(s).end())

#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command

const int INF=0x3f3f3f3f;

typedef long long Int;

typedef pair<int,int> pii;

/*
#ifdef MYDEBUG
#include"debug.h"
#include"print.h"
#endif
*/
// }}}

const Int m = 1, M = 1000000000000000000ll;

int main(){
	int n;
	cin>>n;
	vector<Int> b(n);
	REP(i,n)cin>>b[i];
	pair<Int,Int> v(0,1);//const, a_0
	pair<Int,Int> rng(m,M);
	Int a;
	REP(i,n){
		//judge
		pair<Int,Int> v2;
		if(i%2==0){
			v2.first = -v.first;
			v2.second = -v.second;
			v2.first+=b[i];
		}else{
			v2.first = v.first;
			v2.second = v.second;
			v2.first-=b[i];
		}
//		cerr<<v2.first<<" "<<v2.second<<endl;
		v = v2;
//		cout<<v.first<<" "<<v.second<<endl;
		Int l,r;
		if(v.second==1){
			l = m-v.first, r = M-v.first;
		}else if(v.second==-1){
			l = v.first-M, r = v.first-m;
		}
		rng.first=max(rng.first,l);
		rng.second=min(rng.second,r);
		if(rng.first>rng.second){
			cout<<-1<<endl;
			return 0;
		}
		if(i==n-1)a = rng.first;
	}
	cout<<n+1<<endl;
	REP(i,n){
		cout<<a<<endl;
		assert(m<=a and a<=M);
		if(i%2==0){
			a = b[i] - a;
		}else{
			a = a - b[i];
		}
	}
	cout<<a<<endl;
	assert(m<=a and a<=M);

	return 0;
}
0