Submission #49806

#TimeUsernameProblemLanguageResultExecution timeMemory
49806mra2322001Bank (IZhO14_bank)C++14
71 / 100
1096 ms92504 KiB
#include <bits/stdc++.h> #define f0(i, n) for(int i=(0); i<n; i++) #define f1(i, n) for(int i=(1); i<=n; i++) #define bit(x, y) (((x) >> (y))&1) using namespace std; typedef long long ll; const int N = 22; int n, m, a[N], b[N]; int f[22][1 << 20]; vector <vector <int> > t[N]; int calc(int i, int s){ if(f[i][s] >= 0) return f[i][s]; if(i == n + 1){ cout << "YES"; exit(0); } int &ans = f[i][s]; ans = 0; for(auto x:t[i]){ bool ok = 1; for(auto y:x){ if(bit(s, y)) ok = 0; } if(ok){ int r = s; for(auto y:x){ r = r + (1 << y); } ans = ans | calc(i + 1, r); if(ans) return ans; } } return ans; } main(){ ios_base::sync_with_stdio(0); cin >> n >> m; f1(i, n) cin >> a[i]; f1(i, m) cin >> b[i]; memset(f, -1, sizeof(f)); for(int i = 1; i <= (1 << m); i++){ int val = 0; vector <int> save; f0(j, m){ if(bit(i, j)) val += b[j + 1]; if(bit(i, j)){ save.push_back(j); } } f1(j, n){ if(val==a[j]) t[j].push_back(save); } } calc(1, 0); cout << "NO"; }

Compilation message (stderr)

bank.cpp:39:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...