Submission #106289

#TimeUsernameProblemLanguageResultExecution timeMemory
106289FrankenweenBank (IZhO14_bank)C++14
100 / 100
101 ms552 KiB
#include <bits/stdc++.h> //#define _FORTIFY_SOURCE 0 //#pragma GCC optimize("Ofast") //#pragma GCC optimize("no-stack-protector") //#pragma GCC optimize("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define ull unsigned long long #define pii pair<ll, ll> #define mp make_pair #define ll long long #define ld long double #define pb push_back #define deb(x) cout << #x << " = " << x << endl #define all(x) x.begin(), x.end() #define vi vector<ll> const ll mod = (ll)1e9 + 7; const ll inf = (ll)1e18; const long double e = 2.718281828459; const long double pi = atan2l(0, -1); using namespace std; template <class T> istream& operator>>(istream &in, vector<T> &arr) { for (T &cnt : arr) { in >> cnt; } return in; }; void solve() { ll n, m; cin >> n >> m; vector<ll> a(n), b(m); cin >> a >> b; vector<bool> used((1 << m), false); random_shuffle(all(b)); vector<ll> need = a; function<bool(int, int)> sosatb = [&](int gay, int msk) { used[msk] = true; if (gay == n) { return true; } for (int i = 0; i < m; i++) { if ((msk & (1 << i)) or need[gay] < b[i] or used[(msk | (1 << i))]) { continue; } need[gay] -= b[i]; bool ans; if (need[gay] == 0) { ans = sosatb(gay + 1, (msk | (1 << i))); } else { ans = sosatb(gay, (msk | (1 << i))); } need[gay] += b[i]; if (ans) { return true; } } return false; }; if (sosatb(0, 0)) { cout << "YES"; } else { cout << "NO"; } } int main() { #ifndef LOCAL ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #else freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif cout.precision(30); srand(time(0)); cout.setf(ios::fixed); solve(); 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...