結果

問題 No.4 おもりと天秤
ユーザー Yamyuki
提出日時 2016-12-26 13:47:29
言語 C90
(gcc 12.3.0)
結果
TLE  
実行時間 -
コード長 504 bytes
コンパイル時間 364 ms
コンパイル使用メモリ 22,144 KB
実行使用メモリ 7,972 KB
最終ジャッジ日時 2024-12-14 23:45:37
合計ジャッジ時間 7,156 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22 TLE * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:20:9: warning: implicit declaration of function ‘qsort’ [-Wimplicit-function-declaration]
   20 |         qsort(w,n,sizeof(int),cmp);
      |         ^~~~~
main.c:15:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   15 |         scanf("%d",&n);
      |         ^~~~~~~~~~~~~~
main.c:17:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   17 |                 scanf("%d",&w[i]);
      |                 ^~~~~~~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>
int cmp(const void*a,const void*b){
	return *(int*)a-*(int*)b;
}
int check(int *w,int l,int s){
	if(s==0) return 1;
	if(s<w[0]) return 0;
	for(;l>=0;l--){
		if(check(w,l-1,s-w[l])) return 1;
	}
	return 0;
}
int main(){
	int i,n,w[128],s=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&w[i]);
		s+=w[i];
	}
	qsort(w,n,sizeof(int),cmp);
	if(s%2==0){
		s/=2;
		if(check(w,n-2,s-w[n-1])) printf("possible\n");
		else printf("impossible\n");
	}else printf("impossible\n");
	return 0;
}
0