結果

問題 No.10 +か×か
ユーザー legosukelegosuke
提出日時 2019-01-09 23:45:34
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,730 bytes
コンパイル時間 1,708 ms
コンパイル使用メモリ 175,244 KB
実行使用メモリ 162,872 KB
最終ジャッジ日時 2023-08-15 17:00:33
合計ジャッジ時間 3,161 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
126,300 KB
testcase_01 AC 34 ms
126,224 KB
testcase_02 AC 34 ms
126,276 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 41 ms
161,076 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 41 ms
140,600 KB
testcase_10 AC 35 ms
130,336 KB
testcase_11 AC 35 ms
128,564 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;
int T;
int A[50];
int dp[51][100010];
using P = tuple<int, int, int>;
P pre[51][100010];

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> T;
  REP(i, N) cin >> A[i];
  
  fill_n((P*)pre, 51*100010, MT(-1,-1,-1));
  dp[0][1] = 1;
  pre[0][1] = MT(-1, -1, -1);
  REP(i, N) REP(j, T+1) if (dp[i][j]) {
    if (j*A[i] <= T) {
      dp[i+1][j*A[i]] |= dp[i][j];
      int y, x, t;
      tie(y, x, t) = pre[i+1][j*A[i]];
      if (t == 0) continue;
      pre[i+1][j*A[i]] = MT(i, j, 1);
    }
    if (i && j+A[i] <= T) {
      dp[i+1][j+A[i]] |= dp[i][j];
      pre[i+1][j+A[i]] = MT(i, j, 0);
    }
  }
  int y = N, x = T;
  string s;
  while (y > 0) {
    int py, px, pt;
    tie(py, px, pt) = pre[y][x];
    if (pt == 0) s = "+" + s;
    else s = "*" + s;
    y = py; x = px;
  }
  cout << s.substr(1) << endl;

  return 0;
}
0