結果

問題 No.451 575
ユーザー kuuso1
提出日時 2016-12-02 01:33:07
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 243 ms / 2,000 ms
コード長 1,769 bytes
コンパイル時間 1,632 ms
コンパイル使用メモリ 115,340 KB
実行使用メモリ 41,200 KB
最終ジャッジ日時 2024-12-16 10:39:05
合計ジャッジ時間 7,169 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 29
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
using BI = System.Numerics.BigInteger;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		BI lmin = 1;
		BI rmax = (BI)1e18;
		
		BI[] A = new BI[N+1];
		A[0] = 0;
		BI sig = 1;
		for(int i=1;i<=N;i++){
			A[i] = (B[i-1] - A[i-1]) * sig;
			sig *= -1;
		}
		
		BI ll = lmin;
		BI rr = rmax;
		
		for(int i=0;i<=N;i++){
			if(i%4 == 0 || i%4 == 3){
				if(A[i]+rr > rmax) rr -= (A[i] + rr - rmax);
				if(A[i]+ll < lmin) ll += (lmin - (A[i] + ll));
			}else{
				if(A[i]-rr < lmin) rr -= (lmin - (A[i] - rr));
				if(A[i]-ll > rmax) ll += ((A[i] - ll) - rmax);
			}
		}
		
		if(lmin <= ll && ll <= rr && rr <= rmax){
			A[0] = ll;
			sig = 1;
			for(int i=1;i<=N;i++){
				A[i] = (B[i-1] - A[i-1]) * sig;
				sig *= -1;
			}
			Console.WriteLine(N+1);
			Console.WriteLine(String.Join("\n",A));
			return;
		}
		Console.WriteLine(-1);
	}
	int N;
	BI[] B;
	public Sol(){
		N = ri();
		B = new BI[N];
		for(int i=0;i<N;i++) B[i] = (BI) rl();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}
0