Submission #954099

#TimeUsernameProblemLanguageResultExecution timeMemory
954099AriadnaBank (IZhO14_bank)C++14
25 / 100
1082 ms262144 KiB
#include <bits/stdc++.h> #define mp make_pair using namespace std; bool pay(int n, int m, vector<int>& a, vector<int>& b) { if (m < n) return false; vector<bool> dp(n); int mask = 0; queue<pair<int, pair<int, int>>> q; q.push(mp(0, mp(0, a[0]))); while (!q.empty()) { int mask = q.front().first; int index = q.front().second.first; int sum = q.front().second.second; q.pop(); for (int i = 0; i < m; ++i) { if (!(mask & (1<<i))) { if (b[i] < sum) { q.push(mp(mask | (1<<i), mp(index, sum - b[i]))); } else if (b[i] == sum) { dp[index] = true; if (index+1 < n) q.push(mp(mask | (1<<i), mp(index+1, a[index+1]))); } } } } return dp[n-1]; } int main() { int n, m; cin >> n >> m; vector<int> a(n), b(m); for (int i = 0; i < n; ++i) cin >> a[i]; for (int j = 0; j < m; ++j) cin >> b[j]; if (pay(n, m, a, b)) cout << "YES\n"; else cout << "NO\n"; return 0; }

Compilation message (stderr)

bank.cpp: In function 'bool pay(int, int, std::vector<int>&, std::vector<int>&)':
bank.cpp:10:9: warning: unused variable 'mask' [-Wunused-variable]
   10 |     int mask = 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...