Submission #1112885

#TimeUsernameProblemLanguageResultExecution timeMemory
1112885luvnaBank (IZhO14_bank)C++14
0 / 100
2 ms2584 KiB
#include<bits/stdc++.h> #define all(v) v.begin(), v.end() #define endl "\n" using namespace std; const int N = 21; 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]; for(int i = 1; i < (1 << m); i++) dp[i] = sum[i] = -1; for(int mask = 0; mask < (1 << m); mask++){ for(int i = 0; i < m; i++){ if(mask >> i & 1 && dp[mask ^ (1 << i)] != -1){ int prev_mask = mask ^ (1 << i); int cur_sum = sum[prev_mask] + b[i]; int target = a[dp[prev_mask]]; if(cur_sum < target){ dp[mask] = dp[prev_mask]; sum[mask] = cur_sum; } else if(cur_sum == target){ dp[mask]++; sum[mask] = 0; } } } if(dp[mask] == n){ cout << "YES" << endl; return; } } cout << "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:56:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |         freopen(task".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:57:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |         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...