結果
問題 | No.10 +か×か |
ユーザー |
|
提出日時 | 2014-11-17 16:08:25 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 350 ms / 5,000 ms |
コード長 | 624 bytes |
コンパイル時間 | 703 ms |
コンパイル使用メモリ | 59,592 KB |
実行使用メモリ | 27,008 KB |
最終ジャッジ日時 | 2024-12-14 15:25:54 |
合計ジャッジ時間 | 1,968 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 12 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:24:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 24 | scanf("%d%d",&n,&total); | ~~~~~^~~~~~~~~~~~~~~~~~ main.cpp:26:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 26 | for(int i=0;i<n;i++)scanf("%d",&v[i]); | ~~~~~^~~~~~~~~~~~
ソースコード
#include <string> #include <vector> #include <set> #include <cstdio> #include <cstdlib> using namespace std; set<pair<int,int> >se; void dfs(int total,int cur,vector<int> &v,string s){ if(s.size()==v.size()-1){ if(cur==total){ puts(s.c_str()); exit(0); } return; } if(cur>total||se.find(make_pair(cur,s.size()))!=se.end())return; dfs(total,cur+v[s.size()+1],v,s+'+'); dfs(total,cur*v[s.size()+1],v,s+'*'); se.insert(make_pair(cur,s.size())); } int main(){ int n,total; scanf("%d%d",&n,&total); vector<int>v(n); for(int i=0;i<n;i++)scanf("%d",&v[i]); dfs(total,v[0],v,""); }