Submission #1093898

#TimeUsernameProblemLanguageResultExecution timeMemory
1093898InvMODBank (IZhO14_bank)C++14
100 / 100
76 ms8640 KiB
#include<bits/stdc++.h> using namespace std; template<typename T> bool ckmx(T& a, const T& b){if(a < b) return a = b, true; return false;} template<typename T> bool ckmn(T& a, const T& b){if(a > b) return a = b, true; return false;} const int N = 20; int n, m, a[N], b[N]; int dp[(1<<N)], knapsack[(1<<N)]; 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; //can go through all permutation that form cur mask int cur_wanted = a[dp[mask]-1]; for(int i = 0; i < m; i++){ if(mask>>i&1) continue; int new_mask = mask | (1<<i); if(knapsack[mask] + b[i] == cur_wanted){ if(ckmx(dp[new_mask], dp[mask]+1)){ knapsack[new_mask] = 0; } } else{ if(ckmx(dp[new_mask], dp[mask])){ knapsack[new_mask] = knapsack[mask] + b[i]; } } } } cout << (dp[(1<<m)-1] == n+1 ? "YES" : "NO") <<"\n"; } int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define name "InvMOD" if(fopen(name".INP", "r")){ freopen(name".INP", "r", stdin); freopen(name".OUT", "w", stdout); } solve(); return 0; }

Compilation message (stderr)

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