結果

問題 No.10 +か×か
ユーザー tonyu0tonyu0
提出日時 2019-12-22 10:22:49
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 722 ms / 5,000 ms
コード長 678 bytes
コンパイル時間 622 ms
コンパイル使用メモリ 70,920 KB
実行使用メモリ 319,384 KB
最終ジャッジ日時 2023-08-21 06:26:54
合計ジャッジ時間 5,222 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 142 ms
175,316 KB
testcase_01 AC 138 ms
175,252 KB
testcase_02 AC 138 ms
175,224 KB
testcase_03 AC 720 ms
319,384 KB
testcase_04 AC 334 ms
176,636 KB
testcase_05 AC 345 ms
175,260 KB
testcase_06 AC 722 ms
318,004 KB
testcase_07 AC 511 ms
231,828 KB
testcase_08 AC 266 ms
190,452 KB
testcase_09 AC 209 ms
179,372 KB
testcase_10 AC 151 ms
175,216 KB
testcase_11 AC 147 ms
175,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>

using namespace std;

int n, total, a[50];
string dp[55][100010];
int main()
{
  cin >> n >> total;
  for (int i = 0; i < n; ++i)
    cin >> a[i];

  for (int i = 0; i < 55; ++i)
    for (int j = 0; j < 100010; ++j)
      dp[i][j] = "unko";

  dp[0][a[0]] = "";
  for (int i = 1; i < n; ++i)
  {
    for (int j = 0; j < 100010; ++j)
    {
      if (j + a[i] <= 100000)
        dp[i][j + a[i]] = min(dp[i][j + a[i]], dp[i - 1][j] + '+');
      if (j * a[i] <= 100000)
        dp[i][j * a[i]] = min(dp[i][j * a[i]], dp[i - 1][j] + '-');
    }
  }
  string ans = dp[n - 1][total];
  for (auto &c : ans)
    if (c == '-')
      c = '*';
  cout << ans << '\n';
}
0