結果

問題 No.243 出席番号(2)
ユーザー akakimidori
提出日時 2015-07-11 00:50:31
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 597 bytes
コンパイル時間 354 ms
コンパイル使用メモリ 24,960 KB
実行使用メモリ 13,884 KB
最終ジャッジ日時 2024-07-08 02:37:03
合計ジャッジ時間 10,930 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other WA * 10 TLE * 1 -- * 19
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:7:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    7 |         scanf("%d\n",&N);
      |         ~~~~~^~~~~~~~~~~
main.cpp:13:31: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   13 |         for(i=0;i<N;i++) scanf("%d",&W[i]);
      |                          ~~~~~^~~~~~~~~~~~

ソースコード

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 i;
	for(i=0;i<N;i++) scanf("%d",&W[i]);

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

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

	char *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[j]){
				can[j+W[i]]=1;
			}
		}
	}

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

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