結果
問題 | No.10 +か×か |
ユーザー | ふーらくたる |
提出日時 | 2017-02-17 02:13:27 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 811 ms / 5,000 ms |
コード長 | 1,175 bytes |
コンパイル時間 | 506 ms |
コンパイル使用メモリ | 68,744 KB |
実行使用メモリ | 362,756 KB |
最終ジャッジ日時 | 2023-08-21 06:21:49 |
合計ジャッジ時間 | 4,961 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 54 ms
143,988 KB |
testcase_01 | AC | 56 ms
143,996 KB |
testcase_02 | AC | 55 ms
143,996 KB |
testcase_03 | AC | 811 ms
362,756 KB |
testcase_04 | AC | 611 ms
287,360 KB |
testcase_05 | AC | 55 ms
143,972 KB |
testcase_06 | AC | 806 ms
362,704 KB |
testcase_07 | AC | 612 ms
287,360 KB |
testcase_08 | AC | 190 ms
176,484 KB |
testcase_09 | AC | 298 ms
201,612 KB |
testcase_10 | AC | 57 ms
144,728 KB |
testcase_11 | AC | 55 ms
144,104 KB |
ソースコード
#include <iostream> #include <vector> #include <algorithm> using namespace std; const int MAX_N = 60; const int MAX_TOTAL = 100010; int a[MAX_N]; vector<char> dp[MAX_N][MAX_TOTAL]; int main() { int n, total; cin >> n >> total; for (int i = 0; i < n; i++) { cin >> a[i]; } // 初期化 for (int i = 0; i <= n; i++) { for (int tot = 0; tot <= total; tot++) { dp[i][tot] = vector<char>(i + 1, 0); } } dp[0][a[0]] = vector<char>{'~'}; for (int i = 1; i < n; i++) { for (int tot = 0; tot <= total; tot++) { vector<char> hist; // + if (tot - a[i] >= 0) { hist = dp[i - 1][tot - a[i]]; hist.push_back('+'); dp[i][tot] = max(dp[i][tot], hist); } // * if (tot % a[i] == 0) { hist = dp[i - 1][tot / a[i]]; hist.push_back('*'); dp[i][tot] = max(dp[i][tot], hist); } } } for (int i = 1; i < dp[n - 1][total].size(); i++) { cout << dp[n - 1][total][i]; } cout << endl; return 0; }