結果
問題 |
No.10 +か×か
|
ユーザー |
![]() |
提出日時 | 2023-03-16 14:35:55 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,028 bytes |
コンパイル時間 | 2,914 ms |
コンパイル使用メモリ | 247,944 KB |
実行使用メモリ | 10,268 KB |
最終ジャッジ日時 | 2024-09-18 09:21:00 |
合計ジャッジ時間 | 9,455 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 4 TLE * 1 -- * 7 |
ソースコード
#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; }