結果

問題 No.10 +か×か
ユーザー hotpepsi
提出日時 2015-03-17 16:28:01
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 19 ms / 5,000 ms
コード長 830 bytes
コンパイル時間 681 ms
コンパイル使用メモリ 66,304 KB
実行使用メモリ 23,424 KB
最終ジャッジ日時 2024-12-14 15:28:48
合計ジャッジ時間 1,423 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <sstream>
#include <vector>
#include <cstring>

using namespace std;

int main(int argc, char *argv[])
{
	string s;
	getline(cin, s);
	int N = atoi(s.c_str());
	getline(cin, s);
	int T = atoi(s.c_str());

	static int dp[51][100001];
	memset(dp, 0, sizeof(dp));

	vector<int> A(N);
	getline(cin, s);
	stringstream ss(s);
	for (int i = 0; i < N; ++i) {
		ss >> A[i];
	}
	dp[N][T] = 1;
	for (int i = N-1; i >= 0; --i) {
		for (int j = 0; j <= T; ++j) {
			if (A[i] + j <= T && dp[i+1][A[i] + j]) {
				dp[i][j] = 1;
			}
			if (A[i] * j <= T && dp[i+1][A[i] * j]) {
				dp[i][j] = 1;
			}
		}
	}
	int sum = A[0];
	for (int i = 1; i < N; ++i) {
		if (dp[i+1][sum + A[i]]) {
			cout << "+";
			sum += A[i];
		} else {
			cout << "*";
			sum *= A[i];
		}
	}
	cout << endl;
	return 0;
}
0