結果

問題 No.10 +か×か
ユーザー yuustiyuusti
提出日時 2014-12-05 03:16:13
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,682 bytes
コンパイル時間 855 ms
コンパイル使用メモリ 90,280 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-02 08:51:00
合計ジャッジ時間 2,552 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <climits>
#include <bitset>
#include <cassert>
#include <random>

#ifdef _MSC_VER
#include <agents.h>
#endif

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define UNIQUE(v) (v).erase(unique(ALL(v)), (v).end())
#define MP make_pair
#define MT make_tuple

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int N = 1e2 + 10;
int dp[55][N];
string history[55][N];
int a[55];


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n, total;
	cin >> n >> total;

	rep(i, n) cin >> a[i];

	rep(i, 55) rep(j, N) history[i][j] = string(1, '3');
	dp[1][a[0]] = 1;
	history[1][a[0]] = "";
	FOR(i, 1, n){
		rep(j, total+1){
			if (!dp[i][j]) continue;
			if (j * a[i] <= total){
				dp[i + 1][j * a[i]] = 1;
				history[i + 1][j*a[i]] = min(history[i + 1][j*a[i]], history[i][j] + '2');
			}
		}
		rep(j, total+1){
			if (!dp[i][j]) continue;
			if (j + a[i] <= total){
				dp[i + 1][j + a[i]] = 1;
				history[i + 1][j+a[i]] = min(history[i + 1][j+a[i]], history[i][j] + '1');
			}
		}
	}

	char c[256] = {};
	c['1'] = '+', c['2'] = '*';
	for (auto ch : history[n][total]){
		cout << c[ch];
	}
	cout << endl;

	return 0;
}
0