結果

問題 No.451 575
ユーザー Yamyuki
提出日時 2016-12-02 01:02:55
言語 C90
(gcc 12.3.0)
結果
TLE  
実行時間 -
コード長 638 bytes
コンパイル時間 192 ms
コンパイル使用メモリ 20,736 KB
実行使用メモリ 16,328 KB
最終ジャッジ日時 2024-12-16 09:05:12
合計ジャッジ時間 68,160 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 8 TLE * 21
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:36:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   36 |         scanf("%ld",&n);
      |         ^~~~~~~~~~~~~~~
main.c:38:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   38 |                 scanf("%lld",&a[i]);
      |                 ^~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>

long long a[100000],b[100001];
long n;

int set(long c){
	int f;
	long long i;
	if(c==n+1) return 1;
	if(c==0){
		for(i=1;i<a[0];i++){
			b[0]=i;
			f=set(1);
			if(f) return 1;
		}
		return 0;
	}
	if(c%2==1){
		if(a[c-1]-b[c-1]>0){
			b[c]=a[c-1]-b[c-1];
			f=set(c+1);
			if(f) return 1;
		}
		return 0;
	}
	if(b[c-1]-a[c-1]>0){
		b[c]=b[c-1]-a[c-1];
		f=set(c+1);
		if(f) return 1;
	}
	return 0;
}

int main(){
	long i;
	scanf("%ld",&n);
	for(i=0;i<n;i++){
		scanf("%lld",&a[i]);
	}
	if(set(0)){
		printf("%ld\n",n+1);
		for(i=0;i<n+1;i++){
			printf("%lld\n",b[i]);
		}
		return 0;
	}
	printf("-1\n");
  return 0;
}
0