結果

問題 No.4 おもりと天秤
ユーザー akakimidoriakakimidori
提出日時 2015-07-11 00:43:50
言語 C90
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 558 bytes
コンパイル時間 851 ms
コンパイル使用メモリ 25,288 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-22 10:33:49
合計ジャッジ時間 1,799 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 0 ms
4,380 KB
testcase_06 WA -
testcase_07 AC 0 ms
4,376 KB
testcase_08 WA -
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 WA -
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 0 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:23:5: warning: assignment to ‘int *’ from incompatible pointer type ‘char *’ [-Wincompatible-pointer-types]
  can=(char *)malloc(sizeof(char)*(sum+1));
     ^

ソースコード

diff #

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

int main(void){

	int N;
	scanf("%d\n",&N);

	int *W;
	W=(int *)malloc(sizeof(int)*N);

	int sum=0;
	int i;
	for(i=0;i<N;i++) sum+=W[i];

	if(sum%2!=0){
		printf("impossible\n");
		free(W);
		return 0;
	}

	int *can;
	can=(char *)malloc(sizeof(char)*(sum+1));

	for(i=0;i<=sum;i++) can[i]=0;

	can[0]=1;

	for(i=0;i<N;i++){
		int j;
		for(j=0;j<sum/2;j++){
			if(can[i]){
				can[i+W[i]]=1;
			}
		}
	}

	if(can[sum/2]){
		printf("possible\n");
	} else {
		printf("impossible\n");
	}

	free(W);
	free(can);
	return 0;
}
0