結果

問題 No.10 +か×か
ユーザー not_522not_522
提出日時 2015-08-18 21:32:54
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 667 ms / 5,000 ms
コード長 569 bytes
コンパイル時間 1,430 ms
コンパイル使用メモリ 154,152 KB
実行使用メモリ 303,484 KB
最終ジャッジ日時 2023-08-21 06:13:45
合計ジャッジ時間 3,951 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 667 ms
303,484 KB
testcase_04 AC 131 ms
107,580 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 667 ms
302,368 KB
testcase_07 AC 296 ms
150,376 KB
testcase_08 AC 67 ms
39,540 KB
testcase_09 AC 81 ms
61,640 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, total;
  cin >> n >> total;
  vector<int> a(n);
  for (int& i : a) cin >> i;
  vector<vector<string>> dp(n, vector<string>(total + 1, " "));
  dp[0][a[0]] = "";
  for (int i = 1; i < n; ++i) {
    for (int j = 0; j <= total; ++j) {
      if (dp[i - 1][j] == " ") continue;
      if (j + a[i] <= total) dp[i][j + a[i]] = max(dp[i][j + a[i]], dp[i - 1][j] + "+");
      if (j * a[i] <= total) dp[i][j * a[i]] = max(dp[i][j * a[i]], dp[i - 1][j] + "*");
    }
  }
  cout << dp.back().back() << endl;
}
0