結果

問題 No.10 +か×か
ユーザー CleyLCleyL
提出日時 2020-01-21 18:58:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 700 bytes
コンパイル時間 774 ms
コンパイル使用メモリ 69,052 KB
実行使用メモリ 814,492 KB
最終ジャッジ日時 2023-09-20 03:50:57
合計ジャッジ時間 4,625 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int dfs(int, int)’ 内:
main.cpp:32:1: 警告: 制御が非 void 関数の終りに到達しました [-Wreturn-type]
   32 | }
      | ^

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n,z;
int a[50];
string A;
string Z;
int dfs(int nw,int j){
    //cout << nw << " " << j << " " << A << endl;
    if(j == n){
        if(z==nw){
          Z = A;
          return 1;
        }
        return 0;
    }
    if(nw+a[j] <= z){
        A.push_back('+');
        if(dfs(nw+a[j],j+1)){
          return 1;
        };
        A.pop_back();
    }
    if(nw*a[j] <= z){
        A.push_back('*');
        if(dfs(nw*a[j],j+1)){
          return 1;
        };
        A.pop_back();
    }
}
int main(){
    cin>>n>>z;
    for(int i = 0; n > i; i++){
        cin>>a[i];
    }
    dfs(a[0],1);
    cout << Z << endl;
}
0