結果

問題 No.10 +か×か
ユーザー not_522not_522
提出日時 2015-08-18 21:22:19
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 685 bytes
コンパイル時間 1,188 ms
コンパイル使用メモリ 149,936 KB
実行使用メモリ 23,228 KB
最終ジャッジ日時 2023-09-25 12:55:38
合計ジャッジ時間 1,949 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, total;
  cin >> n >> total;
  vector<int> a(n);
  for (int& i : a) cin >> i;
  vector<vector<int>> dp(n, vector<int>(total + 1, -1));
  dp[0][a[0]] = 0;
  for (int i = 1; i < n; ++i) {
    for (int j = 0; j <= total; ++j) {
      if (dp[i - 1][j] == -1) continue;
      if (j + a[i] <= total) dp[i][j + a[i]] = 0;
      if (j * a[i] <= total && dp[i][j * a[i]] == -1) dp[i][j * a[i]] = 1;
    }
  }
  string res;
  for (int i = n - 1; i >= 1; --i) {
    if (dp[i][total] == 0) {
      res = "+" + res;
      total -= a[i];
    } else {
      res = "*" + res;
      total /= a[i];
    }
  }
  cout << res << endl;
}
0