結果

問題 No.4 おもりと天秤
ユーザー yoshikiriyoshikiri
提出日時 2016-10-30 17:12:44
言語 C90
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 717 bytes
コンパイル時間 243 ms
コンパイル使用メモリ 21,612 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-03 19:51:41
合計ジャッジ時間 867 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 WA -
testcase_05 WA -
testcase_06 AC 0 ms
5,376 KB
testcase_07 WA -
testcase_08 AC 0 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 WA -
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 0 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 WA -
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 0 ms
5,376 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:29:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   29 |         scanf("%d",&n);
      |         ^~~~~~~~~~~~~~
main.c:32:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   32 |                 scanf("%d",&w[j]);
      |                 ^~~~~~~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>

int n;
int w[101],dp[101][101];

int Max(int i,int j){
	return i>j ? i:j;
}

/*i以降でrwを超えない最大のwを返す関数*/
int solver(int i,int rw){
	if(dp[i][rw] != -1) return dp[i][rw];

	int res;
	if(i==n) res=0;
	else if(w[i]>rw){
		res = solver(i+1,rw);
	}
	else{
		res = Max(solver(i+1,rw),solver(i+1,rw-w[i])+w[i]);
	}

	dp[i][rw] = res;
	return res;
}

int main(void){
	int j,k,sum=0;
	scanf("%d",&n);

	for(j=0;j<n;j++)
		scanf("%d",&w[j]);

	for(j=0;j<n;j++)
		sum += w[j];

	for(j=0;j<101;j++)
		for(k=0;k<101;k++)
			dp[j][k] = -1;

	if(sum%2 != 0) printf("impossible\n");
	else if(solver(0,sum/2) == sum/2) printf("possible\n");
	else  printf("impossible\n");

	return 0;
}
0