結果

問題 No.10 +か×か
コンテスト
ユーザー 古寺いろは
提出日時 2015-04-16 00:57:50
言語 C++11(廃止可能性あり)
(gcc 15.2.0 + boost 1.89.0)
結果
AC  
実行時間 19 ms / 5,000 ms
コード長 751 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,332 ms
コンパイル使用メモリ 162,276 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2025-12-06 14:31:23
合計ジャッジ時間 2,014 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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