結果
問題 | No.50 おもちゃ箱 |
ユーザー | hogeover30 |
提出日時 | 2015-03-05 01:03:45 |
言語 | C++11 (gcc 11.4.0) |
結果 |
CE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 677 bytes |
コンパイル時間 | 369 ms |
コンパイル使用メモリ | 51,912 KB |
最終ジャッジ日時 | 2023-09-08 03:36:24 |
合計ジャッジ時間 | 741 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:9:9: error: ‘vector’ was not declared in this scope vector<int> a(n); for(int& v: a) cin>>v; ^~~~~~ main.cpp:9:9: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’? main.cpp:3:1: +#include <vector> using namespace std; main.cpp:9:9: vector<int> a(n); for(int& v: a) cin>>v; ^~~~~~ main.cpp:9:16: error: expected primary-expression before ‘int’ vector<int> a(n); for(int& v: a) cin>>v; ^~~ main.cpp:9:39: error: ‘a’ was not declared in this scope vector<int> a(n); for(int& v: a) cin>>v; ^ main.cpp:10:20: error: ‘a’ was not declared in this scope sort(begin(a), end(a)); ^ main.cpp:13:16: error: expected primary-expression before ‘int’ vector<int> b(m); for(int& v: b) cin>>v; ^~~ main.cpp:13:39: error: ‘b’ was not declared in this scope vector<int> b(m); for(int& v: b) cin>>v; ^ main.cpp:14:14: error: ‘b’ was not declared in this scope sort(b.rbegin(), b.rend()); ^ main.cpp:17:16: error: unable to deduce ‘auto’ from ‘b’ auto t=b; ^
ソースコード
#include <iostream> #include <algorithm> using namespace std; int main() { int n; while (cin>>n) { vector<int> a(n); for(int& v: a) cin>>v; sort(begin(a), end(a)); int m; cin>>m; vector<int> b(m); for(int& v: b) cin>>v; sort(b.rbegin(), b.rend()); int res=m; auto t=b; do { b=t; int k=0; for(int i=0;i<n;++i) { while (k<m and b[k]<a[i]) ++k; if (k==m) break; b[k]-=a[i]; } res=min(res, k); } while (next_permutation(begin(a), end(a))); cout<<(res<m ? res+1 : -1)<<endl; } }