Submission #927058

#TimeUsernameProblemLanguageResultExecution timeMemory
927058May27_thBank (IZhO14_bank)C++17
71 / 100
1061 ms15308 KiB
#include<bits/stdc++.h> #define taskname "bank" using namespace std; void World_Final(); void Solve(); int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); if (fopen(taskname".inp", "r")) { freopen(taskname".inp", "r", stdin); freopen(taskname".out", "w", stdout); } World_Final(); } void World_Final(){ int Tests = 1; //cin >> Tests; while (Tests --) { Solve(); } } void Solve(){ int N, M; cin >> N >> M; vector<int> a(N), b(M); vector<vector<bool>> f(N + 5, vector<bool>((1 << M) + 5, false)); for (int &x : a) cin >> x; for (int &x : b) cin >> x; vector<vector<int>> mp (200005); mp[0].push_back(0); for (int mask = 0; mask < (1 << M); mask ++) { int sum = 0; for (int i = 0; i < M; i ++) { if (mask >> i & 1) sum = sum + b[i]; } mp[sum].push_back(mask); } int tot = 0; f[0][0] = true; bool ans = false; for (int i = 0; i < N; i ++) { tot = tot + a[i]; for (int mask : mp[tot]) { for (int prev : mp[tot - a[i]]) { if ((mask & prev) == prev) { //cout << mask << " " << prev << "\n"; f[i + 1][mask] = max(f[i + 1][mask], f[i][prev]); } } if (i == N - 1) ans |= f[N][mask]; } } cout << (ans ? "YES" : "NO"); } /** **/

Compilation message (stderr)

bank.cpp: In function 'int main()':
bank.cpp:11:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:12:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |         freopen(taskname".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...