結果

問題 No.10 +か×か
コンテスト
ユーザー hanyu
提出日時 2020-12-26 17:17:54
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
結果
AC  
実行時間 569 ms / 5,000 ms
コード長 939 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,962 ms
コンパイル使用メモリ 204,952 KB
実行使用メモリ 305,616 KB
最終ジャッジ日時 2025-12-06 14:57:57
合計ジャッジ時間 4,181 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, t;
  cin >> n >> t;
  
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a.at(i);
  
  vector<vector<string>> dp(n, vector<string>(t + 1, ""));
  dp[0][a[0]] += '!';
  for (int i = 0; i < n - 1; i++) {
    for (int j = 0; j <= t; j++) {
      if (dp[i][j] == "") continue;
      if (j + a[i + 1] <= t) {
        string keep = dp[i][j] + '+';
        if (dp[i + 1][j + a[i + 1]] == "") dp[i + 1][j + a[i + 1]] = keep;
        else if (dp[i + 1][j + a[i + 1]] < keep) dp[i + 1][j + a[i + 1]] = keep;
      }
      if (j * a[i + 1] <= t) {
        string keep = dp[i][j] + '*';
        if (dp[i + 1][j * a[i + 1]] == "") dp[i + 1][j * a[i + 1]] = keep;
        else if (dp[i + 1][j * a[i + 1]] < keep) dp[i + 1][j * a[i + 1]] = keep;
      }
    }
  }
  
  string ans = dp[n - 1][t].substr(1);
  cout << ans << '\n';
}
0