結果

問題 No.10 +か×か
コンテスト
ユーザー not_522
提出日時 2015-08-18 21:32:54
言語 C++11(廃止可能性あり)
(gcc 15.2.0 + boost 1.89.0)
結果
AC  
実行時間 570 ms / 5,000 ms
コード長 569 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,388 ms
コンパイル使用メモリ 167,168 KB
実行使用メモリ 303,804 KB
最終ジャッジ日時 2025-12-06 14:32:15
合計ジャッジ時間 3,771 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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