Submission #258837

#TimeUsernameProblemLanguageResultExecution timeMemory
258837karmaBank (IZhO14_bank)C++14
100 / 100
103 ms8696 KiB
#include <bits/stdc++.h> #define pb emplace_back #define ll long long #define fi first #define se second #define mp make_pair //#define int int64_t using namespace std; const int N = 1 << 20 | 1; const int inf = 1e9 + 1; typedef pair<int, int> pii; pii f[N]; int n, m, a[30], b[30]; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); #define Task "test" if(fopen(Task".inp", "r")) { freopen(Task".inp", "r", stdin); freopen(Task".out", "w", stdout); } cin >> n >> m; a[n] = inf; for(int i = 0; i < n; ++i) cin >> a[i]; for(int i = 0; i < m; ++i) cin >> b[i]; fill(f, f + N, pii(-1, -1)); f[0] = {0, 0}; for(int i = 0; i < (1 << m); ++i) { if(f[i].fi >= n && f[i].se == 0) return cout << "YES", 0; if(f[i].fi == -1) continue; for(int j = 0; j < m; ++j) { if(i >> j & 1) continue; if(f[i].se + b[j] > a[f[i].fi]) continue; if(f[i].se + b[j] == a[f[i].fi]) { f[i ^ (1 << j)] = {f[i].fi + 1, 0}; continue; } f[i ^ (1 << j)] = {f[i].fi, f[i].se + b[j]}; } } cout << "NO"; }

Compilation message (stderr)

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