結果

問題 No.10 +か×か
ユーザー face4
提出日時 2018-11-12 09:10:42
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 10 ms / 5,000 ms
コード長 595 bytes
コンパイル時間 599 ms
コンパイル使用メモリ 65,508 KB
実行使用メモリ 8,444 KB
最終ジャッジ日時 2024-12-14 15:41:16
合計ジャッジ時間 1,195 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

// coding on smartphone
#include<iostream>
using namespace std;

int main(){
	int n, tot, a[51];
	bool dp[51][100001] = {};
	
	cin >> n >> tot;
	for(int i = n-1; i >= 0; i--)	cin >> a[i];
	
	dp[0][tot] = true;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 100001; j++){
			if(!dp[i][j])	continue;
			if(j-a[i] >= 0)	dp[i+1][j-a[i]] = true;
			if(j%a[i] == 0)	dp[i+1][j/a[i]] = true;
		}
	}
	
	int val = a[n-1], pos = n-2;
	while(pos >= 0){
		if(dp[pos][val + a[pos]]){
			val += a[pos];
			cout << "+";
		}else{
			val *= a[pos];
			cout << "*";
		}
		pos--;
	}
	cout << endl;
	
	return 0;
}
0