結果

問題 No.10 +か×か
ユーザー togari_takamototogari_takamoto
提出日時 2015-12-13 06:46:04
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 93 ms / 5,000 ms
コード長 1,078 bytes
コンパイル時間 716 ms
コンパイル使用メモリ 93,568 KB
実行使用メモリ 46,216 KB
最終ジャッジ日時 2023-08-21 06:16:00
合計ジャッジ時間 1,701 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 93 ms
46,216 KB
testcase_04 AC 50 ms
31,304 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 93 ms
46,076 KB
testcase_07 AC 54 ms
31,436 KB
testcase_08 AC 17 ms
11,624 KB
testcase_09 AC 30 ms
19,372 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <iomanip>
#include <numeric>
#include <memory>
#include <limits.h>
#include <set>
#include <cassert>
#include <cmath>
#include <bitset>
#include <functional>
#include <limits>
using namespace std;

typedef long long ll;

#define REP(i,n) for(ll i=0; i<(n); ++i)
#define TEN(x) ((ll)1e##x)
#define ALL(v) (v).begin(), (v).end()

int main(){
	ll n, total;
	cin >> n >> total;
	vector<ll> a(n);
	for (auto&i : a) cin >> i;
	vector<vector<uint64_t>> dp(total+1, vector<uint64_t>(n, numeric_limits<uint64_t>::max()));
	dp[a[0]][0] = 0;
	REP(i,n-1) REP(j, total + 1) {
		auto v = dp[j][i];
		if (j + a[i + 1] <= total && dp[j + a[i + 1]][i + 1] > v) dp[j + a[i + 1]][i + 1] = v;
		v = bitset<64>(v).set(n-2-i).to_ullong();
		if (j * a[i + 1] <= total && dp[j * a[i + 1]][i + 1] > v) dp[j * a[i + 1]][i + 1] = v;
	}

	auto v = bitset<64>(dp[total][n - 1]);
	for (ll i = n - 2; i >= 0; --i) cout << (v.test(i) ? "*" : "+");
	cout << endl;
	return 0;
}
0