結果

問題 No.10 +か×か
ユーザー 久我山菜々久我山菜々
提出日時 2018-09-30 23:03:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,085 bytes
コンパイル時間 1,194 ms
コンパイル使用メモリ 107,140 KB
実行使用メモリ 44,288 KB
最終ジャッジ日時 2024-04-20 13:48:14
合計ジャッジ時間 2,028 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<queue>
#include<numeric>
#include<bitset>

static int const INF{100000000};

int main(int, char**) {
  int n;
  std::cin >> n;
  int total;
  std::cin >> total;
  std::vector<int> as(n);
  for(int i{}; i < n; ++i) {
    std::cin >> as[i];
  }

  static long long const nil = 1LL << 60;
  std::vector<std::vector<long long>> dp(n + 1, std::vector<long long>(total + 1, nil));
  dp[0][as[0]] = 0;
  for(int i{1}; i <= n; ++i) {
    for(int j{}; j <= total; ++j) {
      if(dp[i - 1][j] == nil) continue;
      if(j + as[i] <= total) {
        dp[i][j + as[i]] = std::min(dp[i][j + as[i]], dp[i - 1][j] * 2);
      }
      if(j * as[i] <= total) {
        dp[i][j * as[i]] = std::min(dp[i][j * as[i]], dp[i - 1][j] * 2 + 1);
      }
    }
  }

  long long ans{dp[n][total] / 2};
  if(ans == -1) throw "okasii";
  for(int i{}; i < n - 1; ++i) {
    if(ans % 2) {
      std::cout << '*';
    } else {
      std::cout << '+';
    }
    ans /= 2;
  }
    
  std::cout << std::endl;

  return 0;
}
0