結果

問題 No.10 +か×か
ユーザー furonfuron
提出日時 2023-05-21 20:11:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,364 bytes
コンパイル時間 1,266 ms
コンパイル使用メモリ 129,912 KB
実行使用メモリ 43,804 KB
最終ジャッジ日時 2023-08-23 15:14:23
合計ジャッジ時間 2,246 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 15 ms
18,048 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 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]] = dp[i][j];
				if (j * a[i] <= T) {
					dp[i + 1][j * a[i]] = min(dp[i + 1][j * a[i]], dp[i][j] + (1 << i));
				}
			}
		}
		
	}

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