제출 #738299

#제출 시각아이디문제언어결과실행 시간메모리
738299qrno은행 (IZhO14_bank)C++17
100 / 100
443 ms12996 KiB
#include <bits/stdc++.h> using namespace std; // Template (v1.4.3 - 2023-04-22) (codeforces:cebolinha, atcoder:edu) {{{ #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #define int long long #define fastio ios::sync_with_stdio(false); cin.tie(nullptr) template<class T> using V = vector<T>; template<class T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>; using ii = pair<int, int>; using iii = array<int, 3>; #define all(c) c.begin(), c.end() #define rall(c) c.rbegin(), c.rend() #define sz(x) (int) (x).size() #define pb push_back #define eb emplace_back #define ff first #define ss second #define nemo ><> #define loop(ii, n) for (int ii = 0; ii < (n); ii++) #define cond(c, t, f) ((c) ? (t) : (f)) #define mem(a, b) memset((a), (b), sizeof(a)) #define inbounds(x, l, r) ((l) <= (x) && (x) <= (r)) #define L1(res...) [&](auto x){ return res; } #define L2(res...) [&](auto x, auto y){ return res; } template<class T, class U> inline void miq(T& a, U b){ if (a > b) a = b; } template<class T, class U> inline void maq(T& a, U b){ if (a < b) a = b; } template<class T, class U> auto &operator>>(istream &is, pair<T, U> &p) { return is >> p.ff >> p.ss; } template<class T, class U> auto &operator<<(ostream &os, pair<T, U> const& p) { return os << '(' << p.first << ' ' << p.second << ')'; } const auto EMPTY_STRING = "", SEPARATOR = " "; template<class T> auto &operator>>(istream& is, vector<T> &c) { for (auto &x : c) is >> x; return is; } template<class T> auto &operator<<(ostream& os, vector<T> const &c) { auto sep = EMPTY_STRING; for (auto x : c) os << sep << x, sep = SEPARATOR; return os; } template<class T> auto &operator<<(ostream& os, set<T> const &c) { auto sep = EMPTY_STRING; for (auto x : c) os << sep << x, sep = SEPARATOR; return os; } template<class T> auto &operator<<(ostream& os, multiset<T> const &c) { auto sep = EMPTY_STRING; for (auto x : c) os << sep << x, sep = SEPARATOR; return os; } template<class T> auto &operator<<(ostream& os, unordered_set<T> const &c) { auto sep = EMPTY_STRING; for (auto x : c) os << sep << x, sep = SEPARATOR; return os; } template<class T> auto &operator<<(ostream& os, ordered_set<T> const &c) { auto sep = EMPTY_STRING; for (auto x : c) os << sep << x, sep = SEPARATOR; return os; } template<class T> auto &operator<<(ostream& os, deque<T> const &c) { auto sep = EMPTY_STRING; for (auto x : c) os << sep << x, sep = SEPARATOR; return os; } template<class K, class V> auto &operator<<(ostream& os, map<K,V> const &c) { auto sep = EMPTY_STRING; for (auto x : c) os << sep << x, sep = SEPARATOR; return os; } template<class K, class V> auto &operator<<(ostream& os, unordered_map<K,V> const &c) { auto sep = EMPTY_STRING; for (auto x : c) os << sep << x, sep = SEPARATOR; return os; } template<class... A> void in(A &...a) { ((cin >> a), ...); } template<class... A> void out(A const&... a) { auto sep = EMPTY_STRING; ((cout << sep << a, sep = SEPARATOR), ...); cout << '\n'; } template<class... A> void print(A const&... a) { ((cout << a), ...); } #define var(x) "[", #x, " ", x, "] " template<class... A> void db(A const&... a) { ((cout << (a)), ...); cout << endl; } //}}} const int MAXN = 20; const int MAXS = 1000 + 8; // This will probably TLE in the case that there // are many people with the same sum auto main() -> signed { fastio; int n, m; in(n, m); V<int> a(n), b(m); in(a, b); V<V<int>> ways(MAXS); for (int mask = 0; mask < 1 << m; mask++) { int sum = 0; for (int bit = 0; bit < m; bit++) { if (mask & (1 << bit)) { sum += b[bit]; } } if (sum < MAXS) ways[sum].pb(mask); } vector reach(n+1, V<bool>(1<<m)); reach[0][0] = true; for (int i = 0; i < n; i++) { for (int mask = 0; mask < 1 << m; mask++) { if (!reach[i][mask]) continue; for (auto sum_mask : ways[a[i]]) { if (mask & sum_mask) continue; reach[i+1][mask | sum_mask] = true; } } } if (any_of(all(reach[n]), L1(x))) out("YES"); else out("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...