結果
問題 | No.10 +か×か |
ユーザー |
![]() |
提出日時 | 2020-05-02 01:09:53 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 791 ms / 5,000 ms |
コード長 | 775 bytes |
コンパイル時間 | 769 ms |
コンパイル使用メモリ | 78,368 KB |
実行使用メモリ | 336,952 KB |
最終ジャッジ日時 | 2024-12-14 15:44:39 |
合計ジャッジ時間 | 4,377 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 12 |
ソースコード
#include <algorithm> #include <iostream> #include <vector> #include <cassert> using namespace std; template<class T> inline bool chmax(T &a, T b) { return a < b ? (a = b, 1) : 0; } int main() { assert('*' < '+' && '+' < '@'); int n; cin >> n; int total; cin >> total; vector<int> a(n); for (auto &ai: a) cin >> ai; vector<vector<string>> dp(n, vector<string>(total + 1)); dp[0][a[0]] = "@"; for (int i = 0; i + 1 < n; i++) for (int j = 0; j <= total; j++) { if (j + a[i + 1] <= total) { chmax(dp[i + 1][j + a[i + 1]], dp[i][j] + "+"); } if (j * a[i + 1] <= total) { chmax(dp[i + 1][j * a[i + 1]], dp[i][j] + "*"); } } cout << dp.back()[total].substr(1) << endl; return 0; }