Submission #392646

#TimeUsernameProblemLanguageResultExecution timeMemory
392646vanicBank (IZhO14_bank)C++14
71 / 100
1093 ms368 KiB
#include <cstdio> #include <cmath> #include <algorithm> #include <bitset> #include <vector> using namespace std; const int maxn=20; int n, m; int a[maxn]; int b[maxn]; vector < int > komb[maxn]; int val; void rek(int x, int y, int br){ if(br==a[x]){ komb[x].push_back(val); return; } if(y==m || br>a[x]){ return; } br+=b[y]; val+=(1<<y); rek(x, y+1, br); val-=(1<<y); br-=b[y]; rek(x, y+1, br); } bool cmp(vector < int > &a, vector < int > &b){ return a.size()<b.size(); } bool probaj(int x, int sad){ if(x==n){ return 1; } for(int i=0; i<(int)komb[x].size(); i++){ if(!(komb[x][i]&sad) && probaj(x+1, sad|komb[x][i])){ return 1; } } return 0; } int main(){ scanf("%d%d", &n, &m); for(int i=0; i<n; i++){ scanf("%d", a+i); } for(int i=0; i<m; i++){ scanf("%d", b+i); } for(int i=0; i<n; i++){ rek(i, 0, 0); } sort(komb, komb+n, cmp); if(probaj(0, 0)){ printf("YES\n"); } else{ printf("NO\n"); } return 0; }

Compilation message (stderr)

bank.cpp: In function 'int main()':
bank.cpp:51:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   51 |  scanf("%d%d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~
bank.cpp:53:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   53 |   scanf("%d", a+i);
      |   ~~~~~^~~~~~~~~~~
bank.cpp:56:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   56 |   scanf("%d", b+i);
      |   ~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...