結果

問題 No.10 +か×か
ユーザー 久我山菜々
提出日時 2018-09-30 23:03:51
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,085 bytes
コンパイル時間 1,253 ms
コンパイル使用メモリ 104,528 KB
最終ジャッジ日時 2025-01-06 14:13:24
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 3 WA * 9
権限があれば一括ダウンロードができます

ソースコード

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