結果

問題 No.10 +か×か
ユーザー 古寺いろは古寺いろは
提出日時 2015-04-16 00:57:50
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 17 ms / 5,000 ms
コード長 751 bytes
コンパイル時間 1,205 ms
コンパイル使用メモリ 148,768 KB
実行使用メモリ 4,692 KB
最終ジャッジ日時 2023-08-21 06:12:13
合計ジャッジ時間 1,937 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 16 ms
4,692 KB
testcase_04 AC 7 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 17 ms
4,624 KB
testcase_07 AC 8 ms
4,380 KB
testcase_08 AC 5 ms
4,380 KB
testcase_09 AC 6 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;


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

	long long inf = 1ll << N;

	vector<long long> dp(total + 1, inf);
	dp[A[0]] = 0;
	for (int i = 1; i < N; i++)
	{
		vector<long long> dp2(total + 1, inf);
		for (int j = 0; j <= total; j++)
		{
			if (dp[j] == inf) continue;
			if (j + A[i] <= total){
				dp2[j + A[i]] = min(dp2[j + A[i]], dp[j] * 2);
			}
			if (j * A[i] <= total){
				dp2[j * A[i]] = min(dp2[j * A[i]], dp[j] * 2 + 1);
			}
		}
		dp = dp2;
	}
	for (int i = 0; i < N - 1; i++)
	{
		if ((dp[total] >> (N - 2 - i)) % 2 == 1){
			cout << "*";
		}
		else cout << "+";
	}
	cout << endl;
	cin >> N;
}



0