Submission #1093888

#TimeUsernameProblemLanguageResultExecution timeMemory
1093888ezGeometryBank (IZhO14_bank)C++14
100 / 100
74 ms8656 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int n, m; cin >> n >> m; vector<int> sal(n); for (int i = 0; i < n; i++) { cin >> sal[i]; } vector<int> bank(m); for (int j = 0; j < m; j++) { cin >> bank[j]; } // dp on which bank notes we have used, <current user, amount money given> vector<pair<int, int>> dp(1 << m, make_pair(-1, 0)); dp[0] = make_pair(0, 0); for (int i = 0; i < (1 << m); i++) { if (dp[i].first == -1) { continue; } if (dp[i].first == n) { cout << "YES\n"; return 0; } for (int j = 0; j < m; j++) { if ((1 << j) & i) { continue; } pair<int, int> cur = dp[i]; cur.second += bank[j]; if (cur.second > sal[dp[i].first]) { continue; } if (cur.second == sal[dp[i].first]) { cur.first++; cur.second = 0; } dp[i ^ (1 << j)] = cur; } } cout << "NO\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...