제출 #1167949

#제출 시각아이디문제언어결과실행 시간메모리
1167949SulABank (IZhO14_bank)C++20
100 / 100
119 ms4508 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; using namespace chrono; template<typename T> using ordered_set = tree<T, null_type, less_equal<>, rb_tree_tag, tree_order_statistics_node_update>; #define all(a) (a).begin(), (a).end() short dp[1 << 20], mleft[1 << 20]; short a[20], b[20]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); short n,m; cin >> n >> m; for (short i = 0; i < n; cin >> a[i++]); for (short i = 0; i < m; cin >> b[i++]); for (int mask = 1; mask < 1 << m; mask++) { pair<short,short> best = {-1, -1}; for (short i = 0; i < m; i++) if ((mask >> i) & 1) { int cur_people = dp[mask ^ (1 << i)]; int cur_left = mleft[mask ^ (1 << i)]; if (cur_left + b[i] == a[cur_people]) cur_left = 0, cur_people++; else if (cur_left + b[i] < a[cur_people]) cur_left += b[i]; best = max(best, {cur_people, cur_left}); } tie(dp[mask], mleft[mask]) = best; // cout << mask << " " << dp[mask] << " " << mleft[mask] << "\n"; if (dp[mask] == n) { cout << "YES\n"; return 0; } } cout << "NO"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...