結果
| 問題 |
No.10 +か×か
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-08-21 16:38:52 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 52 ms / 5,000 ms |
| コード長 | 1,140 bytes |
| コンパイル時間 | 1,641 ms |
| コンパイル使用メモリ | 163,464 KB |
| 実行使用メモリ | 46,848 KB |
| 最終ジャッジ日時 | 2024-12-14 15:31:03 |
| 合計ジャッジ時間 | 2,583 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 |
ソースコード
#include <bits/stdc++.h>
#define rep(i, a) rep2 (i, 0, a)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define repr(i, a) repr2 (i, 0, a)
#define repr2(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define asn(a, b, c) fill_n(&(b), sizeof(a) / sizeof(b), c)
using namespace std;
typedef long long ll;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
template<typename T> inline bool umin(T &a, T b) {
return b < a && (a = b, true);
}
ll dp[55][101010];
int main() {
const ll inf = 1ll << 60;
asn(dp, **dp, inf);
int N;
int total;
cin >> N >> total;
vector<ll> A(N);
rep (i, N) cin >> A[i];
dp[0][A[0]] = 0;
A.erase(A.begin());
N--;
rep (i, N) {
rep (j, total + 1) {
if (dp[i][j] == inf) continue;
if (j + A[i] <= total) {
umin(dp[i + 1][j + A[i]], dp[i][j] << 1 | 0);
}
if (j * A[i] <= total) {
umin(dp[i + 1][j * A[i]], dp[i][j] << 1 | 1);
}
}
}
vector<int> ans;
ll x = dp[N][total];
rep (i, N) {
ans.push_back(x & 1);
x >>= 1;
}
reverse(ans.begin(), ans.end());
rep (i, N) {
if (ans[i] & 1) {
cout << "*";
} else {
cout << "+";
}
}
cout << endl;
return 0;
}