結果

問題 No.10 +か×か
ユーザー 👑 CleyL
提出日時 2020-01-21 18:58:42
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
RE  
実行時間 -
コード長 700 bytes
コンパイル時間 710 ms
コンパイル使用メモリ 70,136 KB
実行使用メモリ 8,448 KB
最終ジャッジ日時 2024-07-06 00:07:55
合計ジャッジ時間 2,617 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 2 RE * 10
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int dfs(int, int)':
main.cpp:32:1: warning: control reaches end of non-void function [-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