Submission #664646

#TimeUsernameProblemLanguageResultExecution timeMemory
664646longvuBank (IZhO14_bank)C++14
0 / 100
40 ms1472 KiB
/** * author: longvu * created: 11/27/22 14:55:09 **/ #include<bits/stdc++.h> using namespace std; #define int long long #define sz(x) ((int)x.size()) #define all(x) (x).begin(), (x).end() const int INF = numeric_limits<int>::max(); const int naxn = (int)(21); const int naxm = (int)(19001); const int mod = 1e9 + 7; template<class X, class Y> bool maximize(X& x, const Y y) { if (y > x) {x = y; return true;} return false; } template<class X, class Y> bool minimize(X& x, const Y y) { if (y < x) {x = y; return true;} return false; } int a[naxn], b[naxn], cnt[(1 << naxn)]; vector<int> memo[naxm]; bitset<(1 << naxn)> vis[naxn], dp[naxn]; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); freopen("bank.in","r",stdin);freopen("bank.out","w",stdout); int n, m; cin >> n >> m; for (int i = 0; i < n; ++i) { cin >> a[i]; } for (int i = 0; i < m; ++i) { cin >> b[i]; } for (int mask = 0; mask < (1 << m); ++mask) { int sum = 0; for (int i = 0; i < m; ++i) { if (mask & (1 << i)) { sum += b[i]; } } cnt[mask] = __builtin_popcount(mask); memo[sum].push_back(mask); } function<bool(int, int)> solve = [&](int i, int mask) { if (i == n) { return true; } if (vis[i][mask]) { return (bool)(dp[i][mask]); } bool res = false; for (auto z : memo[a[i]]) { if (!(mask & z) && n - cnt[mask] + cnt[z] >= n - 1 - i && solve(i + 1, mask | z)) { res = true; break; } } vis[i][mask] = true; dp[i][mask] = res; return res; }; cout << (solve(0, 0) ? "YES" : "NO") << '\n'; return 0; }

Compilation message (stderr)

bank.cpp: In function 'int32_t main()':
bank.cpp:34:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |     freopen("bank.in","r",stdin);freopen("bank.out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
bank.cpp:34:41: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |     freopen("bank.in","r",stdin);freopen("bank.out","w",stdout);
      |                                  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...