結果

問題 No.10 +か×か
ユーザー kenken714kenken714
提出日時 2019-04-18 19:49:58
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 12 ms / 5,000 ms
コード長 1,093 bytes
コンパイル時間 530 ms
コンパイル使用メモリ 76,648 KB
実行使用メモリ 8,160 KB
最終ジャッジ日時 2023-08-21 06:25:45
合計ジャッジ時間 1,270 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll n, d, s[60];
string ans;
bool dp[60][110000];
int main() {
	cin >> n >> d;
	REP(i, n) cin >> s[i];
	s[n] = d;
	dp[n][d] = true;
	FORR(i, n - 1, 1) {
		REP(j, 110000) {
			if (dp[i + 1][j]) {
				if (j % s[i] == 0)dp[i][j / s[i]] = true;
				if (j >= s[i])dp[i][j - s[i]] = true;
			}
		}
	}
	ll now = s[0];
	REPO(i, n - 1) {
		if (dp[i + 1][now + s[i]]) {
			ans.push_back('+');
			now += s[i];
		}
		else {
			ans.push_back('*');
			now *= s[i];
		}
	}
	cout << ans << endl;
}



0