結果
問題 |
No.50 おもちゃ箱
|
ユーザー |
![]() |
提出日時 | 2014-10-27 00:08:10 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 806 bytes |
コンパイル時間 | 561 ms |
コンパイル使用メモリ | 42,412 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-30 13:42:40 |
合計ジャッジ時間 | 1,999 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 4 |
other | AC * 2 WA * 36 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:11:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 11 | scanf("%d",&n);//%d%d%d%d",&n,&v,&x,&y,&ax,&ay); | ~~~~~^~~~~~~~~ main.cpp:14:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 14 | scanf("%d",&c[i]); | ~~~~~^~~~~~~~~~~~ main.cpp:16:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 16 | scanf("%d",&m); | ~~~~~^~~~~~~~~ main.cpp:18:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 18 | scanf("%d",&v[i]); | ~~~~~^~~~~~~~~~~~
ソースコード
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> #include <algorithm> using namespace std; //namaega 184 int main(){ int n,m; scanf("%d",&n);//%d%d%d%d",&n,&v,&x,&y,&ax,&ay); int c[100],v[100]; for(int i=0;i<n;i++){ scanf("%d",&c[i]); } scanf("%d",&m); for(int i=0;i<m;i++){ scanf("%d",&v[i]); } sort(v,v+m); int dp[3001]={}; dp[0]=1; int last=0; const int mm=(1<<n); int s[3001]={}; for(int i=0;i<mm;i++){ if(!s[i]){ int a=i; //printf("%d\n",i); for(int j=0;(1<<j)<=i;j++){ if((i>>j)%2)s[i]+=c[j]; } } } sort(s,s+mm); int ans=0; m--; for(int j=mm-1;j>0;j--){ if(v[m]>=s[j]){ ans++; j=(~0&~j); j++; m--; if(m<0)break; } } printf("%d\n",m>=0?ans:-1); return 0; }