結果

問題 No.10 +か×か
ユーザー r_dream0r_dream0
提出日時 2017-02-02 22:44:35
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 38 ms / 5,000 ms
コード長 732 bytes
コンパイル時間 420 ms
コンパイル使用メモリ 54,284 KB
実行使用メモリ 83,360 KB
最終ジャッジ日時 2023-08-21 06:21:38
合計ジャッジ時間 1,485 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
83,092 KB
testcase_01 AC 23 ms
83,176 KB
testcase_02 AC 23 ms
83,352 KB
testcase_03 AC 36 ms
83,092 KB
testcase_04 AC 26 ms
83,072 KB
testcase_05 AC 23 ms
83,100 KB
testcase_06 AC 38 ms
83,032 KB
testcase_07 AC 28 ms
83,096 KB
testcase_08 AC 25 ms
83,092 KB
testcase_09 AC 27 ms
83,060 KB
testcase_10 AC 23 ms
83,360 KB
testcase_11 AC 23 ms
83,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstring>
using namespace std;

int N;
int total;
int A[50];
unsigned long long dp[51][200000];
int main() {
  cin >> N >> total;
  for(int i = 0; i < N; i++) cin >> A[i];
  memset(dp, -1, sizeof(dp));
  dp[1][A[0]] = 0;
  for(int i = 1; i < N; i++) {
    for(int j = 0; j <= total; j++) {
      if(dp[i][j] != -1) {
        if(j * A[i] <= total) dp[i + 1][j * A[i]] = min(dp[i + 1][j * A[i]], dp[i][j] * 2 + 1);
        if(j + A[i] <= total) dp[i + 1][j + A[i]] = min(dp[i + 1][j + A[i]], dp[i][j] * 2);
      }
    }
  }
  string s;
  for(int i = N; i >= 2; i--) {
    if(dp[N][total] % 2 == 0) {
      s = "+" + s;
    }else{
      s = "*" + s;
    }
    dp[N][total] /= 2;
  }
  cout << s << endl;
}
0