結果
問題 |
No.10 +か×か
|
ユーザー |
![]() |
提出日時 | 2017-02-17 02:39:46 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 10 ms / 5,000 ms |
コード長 | 962 bytes |
コンパイル時間 | 622 ms |
コンパイル使用メモリ | 57,260 KB |
実行使用メモリ | 9,308 KB |
最終ジャッジ日時 | 2024-12-14 15:38:21 |
合計ジャッジ時間 | 1,115 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 12 |
ソースコード
#include <iostream> #include <cstring> using namespace std; const int MAX_N = 60; const int MAX_TOTAL = 100010; int a[MAX_N]; bool dp[MAX_N][MAX_TOTAL]; int main() { int n, total; cin >> n >> total; for (int i = 0; i < n; i++) { cin >> a[i]; } memset(dp, false, sizeof(dp)); dp[n][total] = true; for (int i = n - 1; i >= 0; i--) { for (int tot = 0; tot <= total; tot++) { if (tot + a[i] <= total) { dp[i][tot] |= dp[i + 1][tot + a[i]]; } if (tot * a[i] <= total) { dp[i][tot] |= dp[i + 1][tot * a[i]]; } } } int idx = 1, cur_total = a[0]; while (idx < n) { if (dp[idx + 1][cur_total + a[idx]]) { cout << "+"; cur_total += a[idx]; } else { cout << "*"; cur_total *= a[idx]; } idx++; } cout << endl; return 0; }