Submission #328562

#TimeUsernameProblemLanguageResultExecution timeMemory
328562Killer2501Bank (IZhO14_bank)C++14
100 / 100
457 ms103276 KiB
#include <bits/stdc++.h> #define ll long long #define pll pair<ll, ll> #define fi first #define se second #define pb push_back #define task "bank" using namespace std; const int N = 25; const ll mod = 1e9 + 7; ll n, m, t, k, a[N], tong, ans, u, v, b[N], pos[N], d[N], dp[21][(1<<21)]; priority_queue< ll, vector<ll>, greater<ll> > pq; ll c[N]; struct dang { ll lc, rc, val, num; }st[N]; vector<ll> adj[N], kq; vector<pll> w; ll pw(ll k, ll n) { ll total = 1; for(; n; n >>= 1) { if(n & 1)total = (total * k) % mod; k = (k * k) % mod; } return total; } string s; void sol() { cin >> n >> m; for(int i = 1; i <= n; i ++)cin >> a[i]; for(int i = 1; i <= m; i ++)cin >> b[i]; for(int i = 1; i < (1<<m); i ++) { ll tong = 0; for(int j = 0; j < m; j ++) { if((i >> j) & 1)tong += b[j+1]; } for(int j = 1; j <= n; j ++)if(a[j] == tong)adj[j].pb(i); } dp[0][0] = 1; for(int i = 0; i < n; i ++) { for(int j = 0; j < (1<<m); j ++) { if(dp[i][j] == 0)continue; for(ll v : adj[i+1]) { if((j & v) == 0) { dp[i+1][(j|v)] = 1; if(i+1 == n) { cout << "YES"; return; } } } } } cout << "NO"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen(task".in", "r")) { freopen(task".in", "r", stdin); freopen(task".out", "w", stdout); } int ntest = 1; //cin >> ntest; while(ntest -- > 0) sol(); } /* 2 6 9 10 5 4 8 6 2 11 */

Compilation message (stderr)

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