結果

問題 No.10 +か×か
ユーザー pekempeypekempey
提出日時 2015-08-21 16:38:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 30 ms / 5,000 ms
コード長 1,140 bytes
コンパイル時間 1,155 ms
コンパイル使用メモリ 149,728 KB
実行使用メモリ 46,820 KB
最終ジャッジ日時 2023-08-21 06:13:47
合計ジャッジ時間 2,063 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
46,760 KB
testcase_01 AC 14 ms
46,820 KB
testcase_02 AC 14 ms
46,796 KB
testcase_03 AC 28 ms
46,752 KB
testcase_04 AC 18 ms
46,748 KB
testcase_05 AC 14 ms
46,756 KB
testcase_06 AC 30 ms
46,820 KB
testcase_07 AC 18 ms
46,748 KB
testcase_08 AC 16 ms
46,804 KB
testcase_09 AC 18 ms
46,764 KB
testcase_10 AC 15 ms
46,760 KB
testcase_11 AC 15 ms
46,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a) rep2 (i, 0, a)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define repr(i, a) repr2 (i, 0, a)
#define repr2(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define asn(a, b, c) fill_n(&(b), sizeof(a) / sizeof(b), c)
using namespace std;
typedef long long ll;
const ll inf = 1e18;
const ll mod = 1e9 + 7;

template<typename T> inline bool umin(T &a, T b) { 
	return b < a && (a = b, true);
}

ll dp[55][101010];

int main() {
	const ll inf = 1ll << 60;
	asn(dp, **dp, inf);

	int N;
	int total;
	cin >> N >> total;

	vector<ll> A(N);
	rep (i, N) cin >> A[i];

	dp[0][A[0]] = 0;
	A.erase(A.begin());
	N--;

	rep (i, N) {
		rep (j, total + 1) {
			if (dp[i][j] == inf) continue;
			if (j + A[i] <= total) {
				umin(dp[i + 1][j + A[i]], dp[i][j] << 1 | 0);
			}
			if (j * A[i] <= total) {
				umin(dp[i + 1][j * A[i]], dp[i][j] << 1 | 1);
			}
		}
	}

	vector<int> ans;
	ll x = dp[N][total];
	rep (i, N) {
		ans.push_back(x & 1);
		x >>= 1;
	}
	reverse(ans.begin(), ans.end());

	rep (i, N) {
		if (ans[i] & 1) {
			cout << "*";
		} else {
			cout << "+";
		}
	}
	cout << endl;

	return 0;
}
0