結果

問題 No.10 +か×か
ユーザー yuustiyuusti
提出日時 2014-12-05 03:16:22
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 635 ms / 5,000 ms
コード長 1,682 bytes
コンパイル時間 674 ms
コンパイル使用メモリ 90,464 KB
実行使用メモリ 339,984 KB
最終ジャッジ日時 2023-08-21 06:08:48
合計ジャッジ時間 4,099 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 105 ms
177,320 KB
testcase_01 AC 106 ms
177,312 KB
testcase_02 AC 106 ms
177,416 KB
testcase_03 AC 633 ms
339,984 KB
testcase_04 AC 119 ms
197,020 KB
testcase_05 AC 107 ms
195,872 KB
testcase_06 AC 635 ms
338,828 KB
testcase_07 AC 283 ms
240,716 KB
testcase_08 AC 139 ms
192,356 KB
testcase_09 AC 129 ms
189,336 KB
testcase_10 AC 106 ms
179,508 KB
testcase_11 AC 104 ms
179,592 KB
権限があれば一括ダウンロードができます

ソースコード

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 = 1e5 + 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