結果

問題 No.10 +か×か
ユーザー legosukelegosuke
提出日時 2019-01-10 00:06:10
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 32 ms / 5,000 ms
コード長 1,360 bytes
コンパイル時間 1,638 ms
コンパイル使用メモリ 166,108 KB
実行使用メモリ 20,788 KB
最終ジャッジ日時 2023-08-21 06:25:24
合計ジャッジ時間 2,277 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 26 ms
19,212 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 32 ms
20,788 KB
testcase_07 AC 7 ms
6,088 KB
testcase_08 AC 6 ms
6,876 KB
testcase_09 AC 9 ms
9,552 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) ((int)(a).size())
#define PB(a) push_back(a)
#define EB(...) emplace_back(__VA_ARGS__)
#define MP(a, b) make_pair(a, b)
#define MT(...) make_tuple(__VA_ARGS__)
#define Bit(n) (1LL << (n))
using namespace std;
using pii = pair<int, int>;
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
const int MOD = 1000000007;
const int INF = 1LL << 30;
const double EPS = 1e-10;

int N, T;
int A[51];
int dp[51][100010];
string ans;

int dfs(int p, int s) {
  if (s > T) return -1;
  if (dp[p][s]) return dp[p][s];
  if (p == N) return s == T ? 1 : -1;
  if (dfs(p+1, s+A[p]) > 0) ans = "+" + ans;
  else if (dfs(p+1, s*A[p]) > 0) ans = "*" + ans;
  else return dp[p][s] = -1;
  return dp[p][s] = 1;
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> T;
  REP(i, N) cin >> A[i];
  dfs(0, 0);
  cout << ans.substr(1) << endl;

  return 0;
}
0