結果

問題 No.10 +か×か
ユーザー yuustiyuusti
提出日時 2014-12-05 03:00:43
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,636 bytes
コンパイル時間 2,408 ms
コンパイル使用メモリ 85,012 KB
実行使用メモリ 44,848 KB
最終ジャッジ日時 2023-09-02 08:50:56
合計ジャッジ時間 1,587 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
28,084 KB
testcase_01 AC 8 ms
27,956 KB
testcase_02 AC 9 ms
27,944 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 9 ms
25,856 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 15 ms
34,232 KB
testcase_10 AC 9 ms
27,916 KB
testcase_11 AC 9 ms
27,988 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];
int prv[55][N];
int a[55];

int n;
void restore(int i, int val){
	if (i > 0){
		int pval = prv[i][val] ? val / a[i - 1] : val - a[i - 1];
		restore(i - 1, pval);
		if(i > 1) cout << (prv[i][val] ? '*' : '+');
		//cout << a[i-1];
	}
}

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

	int total;
	cin >> n >> total;

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

	MEMSET(prv, -1);
	dp[1][a[0]] = 1;
	FOR(i, 1, n){
		rep(j, total){
			if (!dp[i][j]) continue;
			if (j * a[i] <= total){
				dp[i + 1][j * a[i]] = 1;
				prv[i + 1][j * a[i]] = 1;
			}
		}
		rep(j, total){
			if (!dp[i][j]) continue;
			if (j + a[i] <= total){
				dp[i + 1][j + a[i]] = 1;
				prv[i + 1][j + a[i]] = 0;
			}
		}
	}

	restore(n, total);
	cout << endl;

	return 0;
}
0