Submission #691768

#TimeUsernameProblemLanguageResultExecution timeMemory
691768saayan007Bank (IZhO14_bank)C++17
19 / 100
187 ms17736 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pi = pair<int, int>; using pl = pair<long long, long long>; using vi = vector<int>; using vl = vector<long long>; using vpi = vector<pair<int, int>>; using vpl = vector<pair<long long, long long>>; #define fur(i, a, b) for(ll i = a; i <= (ll)b; ++i) #define ruf(i, a, b) for(ll i = a; i >= (ll)b; --i) #define fr first #define sc second #define mp make_pair #define pb emplace_back #define nl "\n" #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define no cout << "NO" << nl;return 0 #define yes cout << "YES" << nl;return 0 int main() { ios::sync_with_stdio(0); cin.tie(0); ll n, m; cin >> n >> m; ll a[n], b[m]; fur(i, 0, n - 1) { cin >> a[i]; } fur(i, 0, m - 1) { cin >> b[i]; } ll M = 1 << m; pl sum[M]; sum[0] = {0, 0}; fur(i, 1, M - 1) { ll amt = 0; fur(j, 0, m - 1) { if(i & (1 << j)) amt += b[j]; } sum[i] = {amt, i}; } sort(sum, sum + M); bool dp[n][M] = {}; // base case dp[0][..] = 1; // sort(a, a + n); ll ptr = lower_bound(sum, sum + M, mp(a[0], -1ll)) - sum; if(ptr == M || sum[ptr].fr > a[0]) { no; } while(ptr < M && sum[ptr].fr == a[0]) { dp[0][sum[ptr].sc] = 1; ++ptr; if(n == 1) { yes; } } ptr = lower_bound(sum, sum + M, mp(a[0], -1ll)) - sum; fur(i, 0, n - 2) { fur(j, ptr, M - 1) { if(sum[j].fr > a[i]) break; ll ptr2 = lower_bound(sum, sum + M, mp(a[i + 1], -1ll)) - sum; if(ptr2 == M || sum[ptr2].fr > a[i + 1]) { no; } fur(k, ptr2, M - 1) { if(sum[k].fr > a[i + 1]) break; ll b1 = sum[j].sc; ll b2 = sum[k].sc; if(b1 + b2 == (b1 | b2) && (b1|b2) == (b1^b2)) { dp[i + 1][b1|b2] = 1; if(i + 1 == n - 1) { yes; } } } } } 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...