結果

問題 No.10 +か×か
ユーザー togari_takamoto
提出日時 2015-12-13 06:46:04
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 103 ms / 5,000 ms
コード長 1,078 bytes
コンパイル時間 982 ms
コンパイル使用メモリ 95,640 KB
実行使用メモリ 46,208 KB
最終ジャッジ日時 2024-12-14 15:33:14
合計ジャッジ時間 1,757 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

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