結果
| 問題 |
No.10 +か×か
|
| コンテスト | |
| ユーザー |
not_522
|
| 提出日時 | 2015-08-18 21:22:19 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 685 bytes |
| コンパイル時間 | 1,358 ms |
| コンパイル使用メモリ | 164,836 KB |
| 実行使用メモリ | 23,296 KB |
| 最終ジャッジ日時 | 2024-07-18 10:15:48 |
| 合計ジャッジ時間 | 1,790 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 7 WA * 5 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, total;
cin >> n >> total;
vector<int> a(n);
for (int& i : a) cin >> i;
vector<vector<int>> dp(n, vector<int>(total + 1, -1));
dp[0][a[0]] = 0;
for (int i = 1; i < n; ++i) {
for (int j = 0; j <= total; ++j) {
if (dp[i - 1][j] == -1) continue;
if (j + a[i] <= total) dp[i][j + a[i]] = 0;
if (j * a[i] <= total && dp[i][j * a[i]] == -1) dp[i][j * a[i]] = 1;
}
}
string res;
for (int i = n - 1; i >= 1; --i) {
if (dp[i][total] == 0) {
res = "+" + res;
total -= a[i];
} else {
res = "*" + res;
total /= a[i];
}
}
cout << res << endl;
}
not_522