結果

問題 No.10 +か×か
ユーザー CleyLCleyL
提出日時 2020-01-21 18:54:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 792 bytes
コンパイル時間 946 ms
コンパイル使用メモリ 79,956 KB
実行使用メモリ 7,580 KB
最終ジャッジ日時 2023-09-20 03:38:23
合計ジャッジ時間 12,129 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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