結果

問題 No.4 おもりと天秤
ユーザー yj1145141919yj1145141919
提出日時 2016-09-13 15:00:55
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 839 bytes
コンパイル時間 662 ms
コンパイル使用メモリ 26,892 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-08 17:10:02
合計ジャッジ時間 1,656 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 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 0 ms
4,376 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,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 0 ms
4,380 KB
testcase_13 AC 0 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 0 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/*
 * douteki.c
 *
 *  Created on: 2016/09/13
 *      Author: admin
 */


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main(){
	char str[10000];
	char *tmp;
	int n=0, i=0, j=0;
	int sum_w=0, half=0;
	int w[100] = {0};
	int check[10001] = {0};

	check[0] = 1;

	fgets(str, sizeof(str), stdin);
	n = atoi(str);

	fgets(str, sizeof(str), stdin);

	tmp = strtok(str, " ");
	w[0] = atoi(tmp);
	sum_w = w[0];

	for(i = 1; i < n; i++){
		tmp = strtok(NULL, " ");
		w[i] = atoi(tmp);
		sum_w += w[i];
	}


	half = sum_w / 2;

	if(sum_w % 2 == 1){
		printf("impossible\n");
		goto end;
	}

	for(i = 0; i < n; i++){
		for(j = sum_w; j >= 0; j--){
			if(check[j] == 1){
				check[w[i] + j] = 1;
			}
		}
	}

	if(check[half] == 1){
		printf("possible\n");
	}
	else{
		printf("impossible\n");
	}

end:
	return 0;
}
0