結果

問題 No.10 +か×か
ユーザー togari_takamototogari_takamoto
提出日時 2015-12-13 05:54:18
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,095 bytes
コンパイル時間 699 ms
コンパイル使用メモリ 93,248 KB
実行使用メモリ 46,168 KB
最終ジャッジ日時 2023-10-13 14:47:14
合計ジャッジ時間 1,808 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
権限があれば一括ダウンロードができます

ソースコード

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) if(dp[j][i]!=numeric_limits<uint64_t>::max()) {
		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;
		if (j * a[i + 1] <= total && dp[j * a[i + 1]][i + 1] > v + 1<<((n-2)-i)) dp[j * a[i + 1]][i + 1] = v + 1<<((n-2)-i);
	}

	for (ll i = n - 2; i >= 0; --i) cout << ((dp[total][n - 1] & (1 << i)) != 0 ? "*" : "+");
	cout << endl;
	return 0;
}
0