結果

問題 No.10 +か×か
ユーザー togari_takamototogari_takamoto
提出日時 2015-12-13 07:08:11
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 98 ms / 5,000 ms
コード長 1,245 bytes
コンパイル時間 695 ms
コンパイル使用メモリ 93,320 KB
実行使用メモリ 46,008 KB
最終ジャッジ日時 2023-08-21 06:16:02
合計ジャッジ時間 1,732 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 98 ms
46,008 KB
testcase_04 AC 50 ms
31,424 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 96 ms
45,996 KB
testcase_07 AC 54 ms
31,344 KB
testcase_08 AC 17 ms
11,680 KB
testcase_09 AC 32 ms
19,400 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 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;
typedef unsigned long long ull;

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

// 1では無く1ULLにしないとバグる
inline bool bit_check(ull x, int i) { return x & 1ULL << i; }
inline ull bit_flip(ull x, int i) { return x | 1ULL << i; }

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 = bit_flip(v, n - 2 - i);
		if (j * a[i + 1] <= total && dp[j * a[i + 1]][i + 1] > v) dp[j * a[i + 1]][i + 1] = v;
	}

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