結果
問題 |
No.50 おもちゃ箱
|
ユーザー |
|
提出日時 | 2020-06-07 08:56:45 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 539 bytes |
コンパイル時間 | 2,338 ms |
コンパイル使用メモリ | 195,124 KB |
最終ジャッジ日時 | 2025-01-10 23:41:01 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 TLE * 1 |
other | AC * 37 TLE * 1 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:27:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 27 | scanf("%d",&n); | ~~~~~^~~~~~~~~ main.cpp:28:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 28 | rep(i,n) scanf("%d",&a[i]); | ~~~~~^~~~~~~~~~~~ main.cpp:29:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 29 | scanf("%d",&m); | ~~~~~^~~~~~~~~ main.cpp:30:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 30 | rep(j,m) scanf("%d",&b[j]); | ~~~~~^~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; const int INF=1<<29; int n,m,a[10],b[10]; int used[10],ans; void dfs(int i){ if(i==n){ ans=min<int>(ans,m-count(used,used+m,0)); return; } rep(j,m) if(used[j]+a[i]<=b[j]) { used[j]+=a[i]; dfs(i+1); used[j]-=a[i]; } } int main(){ scanf("%d",&n); rep(i,n) scanf("%d",&a[i]); scanf("%d",&m); rep(j,m) scanf("%d",&b[j]); sort(a,a+n,greater<int>()); sort(b,b+m); ans=INF; dfs(0); printf("%d\n",ans<INF?ans:-1); return 0; }