結果

問題 No.10 +か×か
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2016-11-07 23:28:23
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,331 bytes
コンパイル時間 1,172 ms
コンパイル使用メモリ 146,592 KB
実行使用メモリ 8,828 KB
最終ジャッジ日時 2023-08-16 14:44:59
合計ジャッジ時間 2,818 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
8,668 KB
testcase_01 AC 6 ms
8,588 KB
testcase_02 AC 6 ms
8,620 KB
testcase_03 RE -
testcase_04 AC 9 ms
8,672 KB
testcase_05 AC 6 ms
8,736 KB
testcase_06 RE -
testcase_07 AC 10 ms
8,668 KB
testcase_08 WA -
testcase_09 RE -
testcase_10 AC 7 ms
8,828 KB
testcase_11 AC 7 ms
8,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;

//dp[i][j] := i 番目まで見て、+の数が j 個
bool dp[55][100010];

int n, total, a[55];

int main(void){
	cin >> n >> total;
	rep(i, n) cin >> a[i];

	rep(i, 55)rep(j, 100010)dp[i][j] = false;
	dp[n - 1][total] = true;

	for (int i = n - 1; i >= 1; --i){
		for (int j = 0; j <= total; ++j){
			if(dp[i][j]){
				if(0 <= j - a[i]){
					dp[i - 1][j - a[i]] = true;
				}
				if(0 <= j / a[i]){
					dp[i - 1][j / a[i]] = true;
				}
			}
		}
	}

	vector<int> ans;
	int now = a[0];
	for (int i = 0; i < n - 1; ++i){
		if(dp[i + 1][now + a[i + 1]]){
			ans.pb(0);
			now += a[i + 1];
		}else{
			ans.pb(1);
			now *= a[i + 1];
		}
	}
	rep(i, ans.size()){
		if(ans[i] == 0){
			printf("+");
		}else{
			printf("*");
		}
	}
	printf("\n");
	return 0;
}
0