Submission #1112886

#TimeUsernameProblemLanguageResultExecution timeMemory
1112886luvnaBank (IZhO14_bank)C++14
100 / 100
78 ms10712 KiB
#include<bits/stdc++.h> #define all(v) v.begin(), v.end() #define endl "\n" using namespace std; const int N = 21; template<class T> bool maximize(T& a, T b) {if(a < b) return a = b, true; return false;} int n, m; int a[N], b[N]; int dp[(1 << 21)+15]; int sum[(1 << 21)+15]; void solve(){ cin >> n >> m; for(int i = 0; i < n; i++) cin >> a[i]; for(int i = 0; i < m; i++) cin >> b[i]; dp[0] = 1; for(int mask = 0; mask < (1 << m); mask++){ if(!dp[mask]) continue; //useless int target = a[dp[mask]-1]; for(int i = 0; i < m; i++){ if(mask >> i & 1) continue; int nxt_mask = mask + (1 << i); if(sum[mask] + b[i] == target){//can satisfy dp[mask]-1 customer if(maximize(dp[nxt_mask], dp[mask]+1)) sum[nxt_mask] = 0; } else{ if(maximize(dp[nxt_mask], dp[mask])) sum[nxt_mask] = sum[mask] + b[i]; } } } cout << (dp[(1 << m)-1] == n+1 ? "YES" : "NO") << endl; } signed main(){ ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0); #define task "task" if(fopen(task".INP", "r")){ freopen(task".INP", "r", stdin); freopen(task".OUT", "w", stdout); } int t; t = 1; //cin >> t; while(t--) solve(); }

Compilation message (stderr)

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