Submission #673617

#TimeUsernameProblemLanguageResultExecution timeMemory
673617MADE_IN_HEAVENBank (IZhO14_bank)C++17
0 / 100
2 ms384 KiB
#include <bits/stdc++.h> using namespace std; #define what(a) cout << (#a) << " is " << (a) << '\n'; const int N = 20; string s; int n , m , a[N] , b[N]; pair<int , int> memo[1 << N]; bool visited[1 << N]; pair<int , int> dp(int mask) { if (mask == 0) { return make_pair(0 , 0); } if (visited[mask]) return memo[mask]; pair<int , int> res = make_pair(-1 , -1); for (int i = 0; i < m; i++) if(mask & (1 << i)) { auto prev = dp(mask - (1 << i)); if(prev.first == -1 || prev.second == -1) continue; int pos = prev.first; if(prev.second + b[i] < a[pos]) res = max(res , make_pair(prev.first , prev.second + b[i])); if(prev.second + b[i] == a[pos]) res = max(res , make_pair(prev.first + 1 , 0)); } visited[mask] = true; memo[mask] = res; if(res.first == n) { cout << "YES\n"; exit(0); } return res; } 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((1 << m) - 1); cout << "NO\n"; return; } int main() { freopen("bank.in" , "r" , stdin); freopen("bank.out" , "w" , stdout); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tt = 1; // cin >> tt; while (tt--) { solve(); } return 0; }

Compilation message (stderr)

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