結果

問題 No.4 おもりと天秤
ユーザー TLwiegehttTLwiegehtt
提出日時 2015-07-16 00:42:32
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 770 bytes
コンパイル時間 195 ms
コンパイル使用メモリ 24,920 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-08 16:20:33
合計ジャッジ時間 1,171 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,384 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

#define NMAX	(100)
#define WMAX	(100)

int main(void){
	int ans = 1;
	int i,j,n;
	
	int wSum = 0;
	int weight[NMAX+10];
	char dp[NMAX+10][(WMAX*WMAX)/2+100];
	
	for(i=0;i<NMAX+10;i++){
		for(j=0;j<WMAX/2+100;j++){
			dp[i][j] = 0;
		}
	}
	dp[0][0] = 1;
	
	scanf("%d", &n);
	
	for(i=0;i<n;i++){
		scanf("%d", &weight[i]);
		wSum = wSum + weight[i];
	}
	
	if(wSum%2 == 0){
		for(i=1;i<=n;i++){
			int w = weight[i-1];
			for(j=0;j<=(wSum/2+10);j++){
				if(dp[i-1][j] == 1){
					int tsum = j + w;
					dp[i][j] = 1;
					if(tsum <= (wSum/2+10)){
						dp[i][tsum] = 1;
					}
				}
			}
		}
		
		if(dp[n][wSum/2] != 1){
			ans = 0;
		}
		
	}else{
		ans = 0;
	}
	
	if(ans == 1){
		printf("possible\n");
	}else{
		printf("impossible\n");
	}
	return 0;
}
0