Submission #1039748

#TimeUsernameProblemLanguageResultExecution timeMemory
1039748FanOfWilliamLinBank (IZhO14_bank)C++14
100 / 100
86 ms10892 KiB
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; /*template <class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; //- insert(x),erase(x) //- find_by_order(k): return iterator to the k-th smallest element //- order_of_key(x): the number of elements that are strictly smaller*/ #define ll long long #define ld long double #define ar array #define vt vector #define pb push_back #define bit(i, x) ((x>>i)&1ULL) #define pf push_front #define all(v) v.begin(), v.end() #define lla(v) v.rbegin(), v.rend() mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); const int MOD=1e9+7; //const int MOD=998244353; ll floor_div(ll x, ll y) { assert(y!=0); if (y<0) { y=-y; x=-x; } if (x>=0) return x/y; return (x+1)/y-1; } ll ceil_div(ll x, ll y) { assert(y!=0); if (y<0) { y=-y; x=-x; } if (x<=0) { return x/y; } return (x-1)/y+1; } const int mxN=25; int n, m; int cover[1<<mxN], lft[1<<mxN], sal[mxN], notes[mxN]; void solve() { //solve here cin >> n >> m; for(int i=0; i<n; ++i) { cin >> sal[i]; } for(int i=0; i<m; ++i) { cin >> notes[i]; } for(int i=0; i<(1<<m); ++i) { cover[i]=-1; lft[i]=-1; } cover[0]=0; lft[0]=0; for(int msk=0; msk<(1<<m); ++msk) { for(int i=0; i<m; ++i) { if(!bit(i, msk)) { continue; } int prv=msk^(1<<i); if(cover[prv]==-1) { continue; } if(notes[i]+lft[prv]<sal[cover[prv]]) { lft[msk]=lft[prv]+notes[i]; cover[msk]=cover[prv]; } else if(notes[i]+lft[prv]==sal[cover[prv]]) { cover[msk]=cover[prv]+1; lft[msk]=0; } } if(cover[msk]==n) { cout << "YES\n"; return; } } cout << "NO\n"; } signed main() { ios::sync_with_stdio(0); cin.tie(0); //freopen("template.inp", "r", stdin); //freopen("template.out", "w", stdout); int TC=1; //cin >> TC; while(TC--) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...