結果
| 問題 | No.10 +か×か |
| コンテスト | |
| ユーザー |
hanyu
|
| 提出日時 | 2020-12-26 17:17:54 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 325 ms / 5,000 ms |
| + 382µs | |
| コード長 | 939 bytes |
| 記録 | |
| コンパイル時間 | 1,156 ms |
| コンパイル使用メモリ | 222,880 KB |
| 実行使用メモリ | 305,760 KB |
| 最終ジャッジ日時 | 2026-07-19 02:48:46 |
| 合計ジャッジ時間 | 3,200 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 13 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, t;
cin >> n >> t;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a.at(i);
vector<vector<string>> dp(n, vector<string>(t + 1, ""));
dp[0][a[0]] += '!';
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j <= t; j++) {
if (dp[i][j] == "") continue;
if (j + a[i + 1] <= t) {
string keep = dp[i][j] + '+';
if (dp[i + 1][j + a[i + 1]] == "") dp[i + 1][j + a[i + 1]] = keep;
else if (dp[i + 1][j + a[i + 1]] < keep) dp[i + 1][j + a[i + 1]] = keep;
}
if (j * a[i + 1] <= t) {
string keep = dp[i][j] + '*';
if (dp[i + 1][j * a[i + 1]] == "") dp[i + 1][j * a[i + 1]] = keep;
else if (dp[i + 1][j * a[i + 1]] < keep) dp[i + 1][j * a[i + 1]] = keep;
}
}
}
string ans = dp[n - 1][t].substr(1);
cout << ans << '\n';
}
hanyu