結果

問題 No.10 +か×か
ユーザー alpha_virginisalpha_virginis
提出日時 2015-03-07 00:13:11
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,075 bytes
コンパイル時間 1,296 ms
コンパイル使用メモリ 70,512 KB
実行使用メモリ 7,624 KB
最終ジャッジ日時 2023-09-06 20:25:54
合計ジャッジ時間 8,198 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <math.h>

#include <iostream>
#include <vector>
#include <list>
#include <algorithm>

long sub_f1(long total, long value, long depth, long limit_depth, std::vector<long>& v, std::vector<char>& ans) {
  long temp;

  if( depth == limit_depth ) {
    return value;
  }
  
  temp = value + v[depth];
  if( temp <= total ) {
    temp = sub_f1(total, temp, depth+1, limit_depth, v, ans);
    if( temp == total ) {
      ans.push_back('+');
      return temp;
    }
  }

  temp = value * v[depth];
  if( temp <= total ) {
    temp = sub_f1(total, temp, depth+1, limit_depth, v, ans);
    if( temp == total ) {
      ans.push_back('*');
      return temp;
    }
  }

  return -1;
}

int main() {

  long i, j;
  long n, m;

  long total;

  std::vector<long> v;
  std::vector<char> ans;

  long temp;

  std::cin >> n >> total;
  for(i = 0; i < n; i++) {
    std::cin >> temp;
    v.push_back(temp);
  }

  sub_f1(total, v[0], 1, n, v, ans);

  for(i = ans.size()-1; i >= 0; i--) {
    std::cout << ans[i];
  }

  std::cout << std::endl;

  return 0;
}

0