結果

問題 No.10 +か×か
ユーザー TLwiegehttTLwiegehtt
提出日時 2015-07-14 07:52:45
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 12 ms / 5,000 ms
コード長 667 bytes
コンパイル時間 452 ms
コンパイル使用メモリ 25,088 KB
実行使用メモリ 6,732 KB
最終ジャッジ日時 2023-08-21 06:12:46
合計ジャッジ時間 1,190 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 0 ms
4,380 KB
testcase_03 AC 12 ms
6,732 KB
testcase_04 AC 9 ms
5,676 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 12 ms
6,600 KB
testcase_07 AC 9 ms
5,796 KB
testcase_08 AC 3 ms
4,600 KB
testcase_09 AC 5 ms
5,500 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

char dp[55][100100];

int main(void){
	int p;
	int i,j,n,total;
	int a[55];
	
	scanf("%d", &n);
	scanf("%d", &total);
	
	for(i=0;i<n;i++){
		scanf("%d", &a[i]);
	}
	
	dp[n][total] = 1;
	for(i=n-1;i>=0;i--){
		for(j=0;j<total+1;j++){
			int tmp = j+a[i];
			dp[i][j] = 0;
			
			if( tmp <= total && dp[i+1][tmp]){
				dp[i][j] = 1;
			}
			tmp = j*a[i];
			if( tmp <= total && dp[i+1][tmp]){
				dp[i][j] = 1;
			}
		}
	}
	
	p = a[0];
	for(i=1;i<n;i++){
		if( (p+a[i]) <= total && dp[i+1][p+a[i]] ){ p+=a[i]; printf("+");	continue;	}
		if( (p*a[i]) <= total && dp[i+1][p*a[i]] ){ p*=a[i]; printf("*");	continue;	}
	}
	
	printf("\n");
	
	return 0;
}
0