結果

問題 No.10 +か×か
ユーザー motimoti
提出日時 2015-07-17 18:47:20
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 908 bytes
コンパイル時間 581 ms
コンパイル使用メモリ 79,596 KB
実行使用メモリ 4,548 KB
最終ジャッジ日時 2023-09-22 17:00:20
合計ジャッジ時間 2,900 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <set>
#include <map>

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;
std::string dp[550][55];

std::string dfs(int now, int idx, string const& str) {
  auto& ret = dp[now][idx];
  if(!ret.empty()) { return ret; }
  ret = "1111111111111111111111111111111111111111111111111111111111111111111111";
  if(idx == N) {
    if(tot != now) { return ret; }
    return ret = str;
  }
  return ret = min(dfs(now+A[idx], idx+1, str + "0"), dfs(now*A[idx], idx+1, str + "1"));
}

int main() {

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

  auto ans = dfs(A[0], 1, "");
  rep(i, ans.size()) {
    cout << (ans[i] == '0' ? '+' : '*');
  }
  cout << endl;

  return 0;
}
0