結果

問題 No.10 +か×か
ユーザー sugim48sugim48
提出日時 2014-12-21 05:29:40
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 32 ms / 5,000 ms
コード長 1,189 bytes
コンパイル時間 606 ms
コンパイル使用メモリ 79,392 KB
実行使用メモリ 23,480 KB
最終ジャッジ日時 2023-08-21 06:09:30
合計ジャッジ時間 1,488 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,492 KB
testcase_01 AC 4 ms
4,844 KB
testcase_02 AC 4 ms
4,896 KB
testcase_03 AC 31 ms
23,456 KB
testcase_04 AC 32 ms
23,480 KB
testcase_05 AC 32 ms
23,340 KB
testcase_06 AC 31 ms
23,304 KB
testcase_07 AC 32 ms
23,364 KB
testcase_08 AC 17 ms
14,068 KB
testcase_09 AC 14 ms
11,904 KB
testcase_10 AC 6 ms
6,464 KB
testcase_11 AC 5 ms
6,252 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	int N, x; cin >> N >> x;
	vector<int> A(N);
	for (int i = 0; i < N; i++)
		cin >> A[i];
	vector< vector<int> > dp(N + 1, vector<int>(100001));
	dp[N][x] = 3;
	for (int i = N - 1; i >= 0; i--)
		for (int j = 0; j <= 100000; j++) {
			if (j + A[i] <= 100000 && dp[i + 1][j + A[i]])
				dp[i][j] += 1;
			if ((ll)j * A[i] <= 100000 && dp[i + 1][j * A[i]])
				dp[i][j] += 2;
		}
	int j = A[0];
	for (int i = 1; i < N; i++)
		if (dp[i][j] % 2) {
			cout << '+';
			j += A[i];
		}
		else {
			cout << '*';
			j *= A[i];
		}
	cout << endl;
}
0