結果

問題 No.10 +か×か
ユーザー pocaristpocarist
提出日時 2015-09-19 14:14:43
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 860 bytes
コンパイル時間 2,016 ms
コンパイル使用メモリ 76,896 KB
実行使用メモリ 23,420 KB
最終ジャッジ日時 2023-09-26 13:36:58
合計ジャッジ時間 1,874 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 1 ms
4,380 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 9 ms
10,120 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 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>

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<int>> dp(N, vector<int>(Total + 1, -1));

	dp[0][A[0]] = 0;
	for (int i = 1; i < N; i++) {
		for (int j = 0; j < Total; j++) {
			if (dp[i-1][j] != -1) {
				int n = j + A[i];
				if (n <= Total)
					dp[i][n] = dp[i - 1][j];
				int m = j * A[i];
				if (m <= Total)
					dp[i][m] = dp[i - 1][j] | (1 << (i - 1));
			}
		}
	}

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