結果

問題 No.10 +か×か
ユーザー momoyuumomoyuu
提出日時 2023-03-16 14:35:55
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,028 bytes
コンパイル時間 3,355 ms
コンパイル使用メモリ 247,516 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-18 13:01:23
合計ジャッジ時間 10,326 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int n,t;
int a[51];
vector<char> ans;
bool dfs(int ni,int now){
    //cout<<ni<<" "<<now<<endl;
    assert(ni<n);
    //cout<<ni<<endl;
    if(now>t) return false;
    int tmp = now + a[ni];
    int tt = now * a[ni];
    //cout<<ni<<" "<<a[ni]<<" "<<tmp<<endl;
    if(ni==n-1){
        //cout<<"aaa2"<<endl;
        if(tmp==t){
            ans.push_back('+');
            return true;
        }else if(tt==t){
            ans.push_back('*');
            return true;
        }
        return false;
    }else if(ni==0){
        return dfs(1,tmp);
    }else{
        ans.push_back('+');
        if(dfs(ni+1,tmp)) return true;
        ans.pop_back();
        ans.push_back('*');
        if(dfs(ni+1,tt)) return true;
        ans.pop_back();
        return false;
    }
    return false;
}

int main(){
    cin>>n>>t;
    //vector<int> a(n);
    for(int i = 0;i<n;i++) cin>>a[i];
    dfs(0,0);
    for(int i = 0;i<ans.size();i++) cout<<ans[i];
    cout<<endl;
}

0