結果
問題 | No.10 +か×か |
ユーザー |
![]() |
提出日時 | 2020-12-26 17:17:54 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 556 ms / 5,000 ms |
コード長 | 939 bytes |
コンパイル時間 | 2,047 ms |
コンパイル使用メモリ | 202,672 KB |
最終ジャッジ日時 | 2025-01-17 07:31:02 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 12 |
ソースコード
#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';}