結果

問題 No.10 +か×か
ユーザー shisyamokongarishisyamokongari
提出日時 2016-08-25 01:52:44
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 839 bytes
コンパイル時間 413 ms
コンパイル使用メモリ 60,888 KB
実行使用メモリ 23,628 KB
最終ジャッジ日時 2023-08-07 20:49:34
合計ジャッジ時間 1,189 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,888 KB
testcase_01 AC 2 ms
5,736 KB
testcase_02 AC 3 ms
5,672 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 3 ms
6,808 KB
testcase_11 AC 3 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cmath>

using namespace std;

#define NMAX 50
#define TotalMAX 100000
int main(){
	
	int N,Total;
	int A[NMAX];
	int dp[50][TotalMAX+1];

	cin>>N;
	cin>>Total;

	for(int i=0;i<N;i++){
		cin>>A[i];
	}

	for(int i=0;i<N;i++){
		for(int j=0;j<=TotalMAX;j++){
			dp[i][j]=-1;
		}
	}

	dp[0][A[0]]=0;

	for(int i=1;i<N;i++){
		for(int j=0;j<=TotalMAX;j++){
			if(dp[i-1][j]!=-1){
				if(j+A[i]<=TotalMAX){
					if(dp[i][j+A[i]]==-1||dp[i-1][j]*10+0<dp[i][j+A[i]]){
						dp[i][j+A[i]]=dp[i-1][j]*10+0;
					}
				}
				if(j*A[i]<=TotalMAX){
					if(dp[i][j*A[i]]==-1||dp[i-1][j]*10+1<dp[i][j*A[i]]){
						dp[i][j*A[i]]=dp[i-1][j]*10+1;
					}
				}
			}
		}
	}

	int ans=dp[N-1][Total];

	for(int i=N-2;i>=0;i--){
		int ansA=(int)(ans/pow(10.0,i))%10;
		if(ansA==0) cout<<"+";
		else cout<<"*";
	}

	cout<<endl;
}

0