結果

問題 No.4 おもりと天秤
ユーザー YamyukiYamyuki
提出日時 2016-12-26 13:47:29
言語 C90
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 504 bytes
コンパイル時間 177 ms
コンパイル使用メモリ 22,144 KB
実行使用メモリ 6,784 KB
最終ジャッジ日時 2024-05-08 17:47:26
合計ジャッジ時間 6,869 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 0 ms
5,376 KB
testcase_03 AC 0 ms
5,376 KB
testcase_04 AC 0 ms
5,376 KB
testcase_05 AC 0 ms
5,376 KB
testcase_06 AC 0 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 0 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 0 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 0 ms
5,376 KB
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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