結果

問題 No.10 +か×か
ユーザー mh72012246mh72012246
提出日時 2016-11-08 13:25:21
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,186 bytes
コンパイル時間 1,302 ms
コンパイル使用メモリ 96,452 KB
実行使用メモリ 814,648 KB
最終ジャッジ日時 2023-08-16 15:01:19
合計ジャッジ時間 4,604 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cmath>
#include <vector>
#include <array>
#include <queue>
#include <set>
#include <map>
#include <sstream>   // istringstream
#include <algorithm> // sort
#include <utility>   // pair
#include <cfloat>    // DBL_MAX

typedef long long ll;
using namespace std;

// const int maxN = 200000;
// bool ps[maxN-1];

int main(){
  ll N, total; // [50, 100,000]
  cin >> N >> total;

  vector<int> As(N);
  for(int i=0; i<N; i++){
    cin >> As[i];
  }

  // main
  queue<pair<int,string> > fomulas;
  fomulas.push(make_pair(total, ""));

  for(int i=N-1; i>0; i--){
    queue<pair<int,string> > next;
    while(!fomulas.empty()){
      // +
      if(fomulas.front().first >= As[i]){
        next.push(make_pair(fomulas.front().first-As[i],
                            "+"+fomulas.front().second));
      }
      // *
      if(fomulas.front().first%As[i] == 0){
        next.push(make_pair(fomulas.front().first/As[i],
                            "*"+fomulas.front().second));
      }

      fomulas.pop();
    }
    fomulas = next;
  }

  // output
  while(fomulas.front().first!=As[0]){ fomulas.pop(); }
  cout << fomulas.front().second << endl;

  return 0;
}
0