結果

問題 No.10 +か×か
ユーザー roiti46roiti46
提出日時 2015-10-11 06:05:43
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 654 ms / 5,000 ms
コード長 840 bytes
コンパイル時間 1,464 ms
コンパイル使用メモリ 162,936 KB
実行使用メモリ 306,944 KB
最終ジャッジ日時 2024-05-08 11:48:07
合計ジャッジ時間 4,917 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
162,688 KB
testcase_01 AC 95 ms
162,696 KB
testcase_02 AC 114 ms
162,812 KB
testcase_03 AC 654 ms
306,944 KB
testcase_04 AC 232 ms
164,096 KB
testcase_05 AC 91 ms
162,816 KB
testcase_06 AC 646 ms
305,664 KB
testcase_07 AC 356 ms
207,556 KB
testcase_08 AC 143 ms
169,600 KB
testcase_09 AC 161 ms
166,324 KB
testcase_10 AC 93 ms
162,816 KB
testcase_11 AC 94 ms
162,712 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];
string 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] = "c";
  dp[0][A[0]] = "";
  REP(i, 1, N) rep(j, T + 1) {
    if (j + A[i] <= T) dp[i][j + A[i]] = min(dp[i][j + A[i]], dp[i - 1][j] + "a");
    if (j * A[i] <= T) dp[i][j * A[i]] = min(dp[i][j * A[i]], dp[i - 1][j] + "b");
  }

  string ans;
  rep(i, N - 1) ans += (dp[N - 1][T][i] == 'a' ? '+':'*');
  cout << ans << endl;
  return 0;
}
0