結果

問題 No.10 +か×か
ユーザー motimoti
提出日時 2015-07-25 00:47:19
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,061 bytes
コンパイル時間 641 ms
コンパイル使用メモリ 77,204 KB
実行使用メモリ 24,924 KB
最終ジャッジ日時 2023-09-23 03:56:01
合計ジャッジ時間 7,436 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
24,924 KB
testcase_01 AC 9 ms
24,824 KB
testcase_02 AC 9 ms
24,828 KB
testcase_03 RE -
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <set>
#include <map>
#include <assert.h>
#include <cstring>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;

int N, tot;
vector<int> A;
int dp[100010][55];

bool dfs(int now, int idx) {
  auto& ope = dp[now][idx];

  if(idx == N) { return now == tot; }

  if(ope != -1) { return true; }

  if(dfs(now+A[idx], idx+1)) {
    ope = 0; return true;
  }
  if(dfs(now*A[idx], idx+1)) {
    ope = 1; return true;
  }
  return false;
}

int main() {

  memset(dp, -1, sizeof dp);
  dp[0][0] = 0;

  cin >> N >> tot;
  rep(i, N) {
    int a; cin >> a;
    A.push_back(a);
  }

  assert(dfs(A[0], 1));

  std::string ans;
  int num = A[0];
  REP(i, 1, N) {
    if(dp[num][i] == 0) {
      ans += '+';
      num += A[i];
    }
    else if(dp[num][i] == 1) {
      ans += '*';
      num *= A[i];
    }
    else {
      assert(false);
    }
  }
  cout << ans << endl;

  return 0;
}
0