結果

問題 No.10 +か×か
ユーザー zimphazimpha
提出日時 2017-12-07 02:18:21
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 32 ms / 5,000 ms
コード長 732 bytes
コンパイル時間 213 ms
コンパイル使用メモリ 33,292 KB
実行使用メモリ 42,796 KB
最終ジャッジ日時 2023-08-21 06:24:05
合計ジャッジ時間 1,119 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
42,772 KB
testcase_01 AC 12 ms
42,764 KB
testcase_02 AC 13 ms
42,712 KB
testcase_03 AC 30 ms
42,708 KB
testcase_04 AC 16 ms
42,788 KB
testcase_05 AC 13 ms
42,796 KB
testcase_06 AC 32 ms
42,788 KB
testcase_07 AC 17 ms
42,756 KB
testcase_08 AC 15 ms
42,768 KB
testcase_09 AC 17 ms
42,752 KB
testcase_10 AC 12 ms
42,712 KB
testcase_11 AC 12 ms
42,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>

using int64 = long long;

const int N = 51, S = 1e5 + 10;

int64 dp[N][S];
int a[N];

int main() {
  memset(dp, -1, sizeof(dp));
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  auto update = [&](int64 &x, int64 y) {
    if (x == -1 || x > y) x = y;
  };
  dp[0][0] = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j <= m; ++j) if (dp[i][j] != -1) {
      if (j + a[i] <= m) update(dp[i + 1][j + a[i]], dp[i][j]);
      if (j * a[i] <= m) update(dp[i + 1][j * a[i]], dp[i][j] | (1ll << (n - i)));
    }
  }
  for (int i = n - 1; i > 0; --i) {
    if (dp[n][m] >> i & 1) putchar('*');
    else putchar('+');
  }
  puts("");
  return 0;
}
0