結果

問題 No.10 +か×か
ユーザー roiti46roiti46
提出日時 2015-10-11 06:37:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 11 ms / 5,000 ms
コード長 918 bytes
コンパイル時間 1,159 ms
コンパイル使用メモリ 159,804 KB
実行使用メモリ 8,364 KB
最終ジャッジ日時 2024-05-08 11:47:29
合計ジャッジ時間 1,701 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 11 ms
8,364 KB
testcase_04 AC 7 ms
8,044 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 11 ms
8,304 KB
testcase_07 AC 8 ms
7,556 KB
testcase_08 AC 4 ms
6,944 KB
testcase_09 AC 4 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (__typeof(a.begin()) x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())

int N, T;
int A[51];
bool dp[51][100005];

int main(void) {
  cin >> N;
  cin >> T;
  rep(i, N) cin >> A[i];
  rep(i, N) rep(j, T + 1) dp[i][j] = false;
  dp[N][T] = true;
  for (int i = N - 1; i > -1; i--) rep(j, T + 1) {
    if (j * A[i] <= T && dp[i + 1][j * A[i]]) dp[i][j] = true;
    if (j + A[i] <= T && dp[i + 1][j + A[i]]) dp[i][j] = true;
  }

  string ans;
  int c = A[0];
  REP(i, 1, N) {
    if (dp[i + 1][c + A[i]]) {
      ans += "+";
      c += A[i];
    } else {
      ans += "*";
      c *= A[i];
    }
  };
  cout << ans << endl;
  return 0;
}
0