結果

問題 No.10 +か×か
ユーザー pocaristpocarist
提出日時 2015-09-19 16:21:08
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 45 ms / 5,000 ms
コード長 1,060 bytes
コンパイル時間 648 ms
コンパイル使用メモリ 78,684 KB
実行使用メモリ 43,176 KB
最終ジャッジ日時 2023-08-21 06:13:55
合計ジャッジ時間 1,483 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 44 ms
43,176 KB
testcase_04 AC 22 ms
29,396 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 45 ms
42,852 KB
testcase_07 AC 24 ms
29,504 KB
testcase_08 AC 10 ms
10,816 KB
testcase_09 AC 14 ms
17,516 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//http://yukicoder.me/problems/29
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <cstdint>
#include <limits>

using namespace std;

int main()
{
	int N;
	cin >> N;
	int Total;
	cin >> Total;
	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}

	vector<vector<int64_t>> dp(N, vector<int64_t>(Total + 1, numeric_limits<int64_t>::max()));

	dp[0][A[0]] = 0;
	for (int i = 1; i < N; i++) {
		for (int j = 1; j <= Total; j++) {
			if (dp[i - 1][j] != numeric_limits<int64_t>::max()) {
				int n = j + A[i];
				if (n <= Total) {
					auto v = dp[i - 1][j];
					if (dp[i][n] > v)
						dp[i][n] = v;
				}
				int m = j * A[i];
				if (m <= Total) {
					auto v = dp[i - 1][j] | (1LL << (N - i));
					if (dp[i][m] > v)
						dp[i][m] = v;
				}
			}
		}
	}

	string ans;
	for (int i = 0; i < N - 1; i++) {
		if (dp[N - 1][Total] & (1LL << (N - i - 1)))
			ans += "*";
		else
			ans += "+";
	}
	cout << ans << endl;
	return 0;
}
0