結果
問題 | No.10 +か×か |
ユーザー | kyuna |
提出日時 | 2020-05-02 01:09:53 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 806 ms / 5,000 ms |
コード長 | 775 bytes |
コンパイル時間 | 726 ms |
コンパイル使用メモリ | 78,664 KB |
実行使用メモリ | 336,684 KB |
最終ジャッジ日時 | 2023-08-21 06:29:36 |
合計ジャッジ時間 | 4,595 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,380 KB |
testcase_01 | AC | 2 ms
4,384 KB |
testcase_02 | AC | 1 ms
4,380 KB |
testcase_03 | AC | 806 ms
336,492 KB |
testcase_04 | AC | 621 ms
220,608 KB |
testcase_05 | AC | 2 ms
4,380 KB |
testcase_06 | AC | 788 ms
336,684 KB |
testcase_07 | AC | 626 ms
221,968 KB |
testcase_08 | AC | 116 ms
50,116 KB |
testcase_09 | AC | 168 ms
77,976 KB |
testcase_10 | AC | 3 ms
4,376 KB |
testcase_11 | AC | 2 ms
4,376 KB |
ソースコード
#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; }