結果
問題 | No.10 +か×か |
ユーザー |
|
提出日時 | 2019-12-22 10:22:49 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 819 ms / 5,000 ms |
コード長 | 678 bytes |
コンパイル時間 | 779 ms |
コンパイル使用メモリ | 70,944 KB |
最終ジャッジ日時 | 2025-01-08 13:50:12 |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 12 |
ソースコード
#include <iostream> using namespace std; int n, total, a[50]; string dp[55][100010]; int main() { cin >> n >> total; for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 0; i < 55; ++i) for (int j = 0; j < 100010; ++j) dp[i][j] = "unko"; dp[0][a[0]] = ""; for (int i = 1; i < n; ++i) { for (int j = 0; j < 100010; ++j) { if (j + a[i] <= 100000) dp[i][j + a[i]] = min(dp[i][j + a[i]], dp[i - 1][j] + '+'); if (j * a[i] <= 100000) dp[i][j * a[i]] = min(dp[i][j * a[i]], dp[i - 1][j] + '-'); } } string ans = dp[n - 1][total]; for (auto &c : ans) if (c == '-') c = '*'; cout << ans << '\n'; }