結果

問題 No.10 +か×か
コンテスト
ユーザー face4
提出日時 2018-11-12 09:10:42
言語 C++14
(gcc 13.3.0 + boost 1.89.0)
結果
AC  
実行時間 13 ms / 5,000 ms
コード長 595 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 448 ms
コンパイル使用メモリ 64,628 KB
実行使用メモリ 8,448 KB
最終ジャッジ日時 2025-12-06 14:37:37
合計ジャッジ時間 1,202 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

// 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