結果

問題 No.10 +か×か
ユーザー furonfuron
提出日時 2023-05-21 22:15:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 45 ms / 5,000 ms
コード長 1,397 bytes
コンパイル時間 1,254 ms
コンパイル使用メモリ 129,616 KB
実行使用メモリ 43,692 KB
最終ジャッジ日時 2023-08-23 15:15:11
合計ジャッジ時間 2,065 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 44 ms
43,692 KB
testcase_04 AC 25 ms
29,972 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 45 ms
43,684 KB
testcase_07 AC 26 ms
30,176 KB
testcase_08 AC 9 ms
11,252 KB
testcase_09 AC 16 ms
18,324 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <queue>
#include <map>
#include <bitset>
#include <set>
#include <stack>
#include <numeric>
#include <unordered_map>
#include <random>

using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vd = vector<double>;
using vs = vector<string>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using vpii = vector<pii>;
using vpll = vector<pll>;
using vpdd = vector<pdd>;
const int inf = (1 << 30) - 1;
const ll INF = 1LL << 60;
//const int MOD = 1000000007;
const int MOD = 998244353;

int main() {
	int n, T;
	cin >> n >> T;
	vi a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	vvl dp(n + 1, vl(T + 1, INF));
	dp[1][a[0]] = 0;
	for (int i = 1; i < n; i++) {
		for (int j = 0; j <= T; j++) {
			if (dp[i][j] != INF) {
				if (j + a[i] <= T)
					dp[i + 1][j + a[i]] = min(dp[i + 1][j + a[i]], dp[i][j] << 1);
				if (j * a[i] <= T) {
					dp[i + 1][j * a[i]] = min(dp[i + 1][j * a[i]], (dp[i][j] << 1) + 1);
				}
			}
		}

	}

	bitset<60> bs(dp[n][T]);
	for (int i = n - 2; i >= 0; i--) {
		if (bs[i] == 0) cout << '+';
		else cout << '*';
	}
	cout << endl;

	return 0;
}
0