Submission #340647

#TimeUsernameProblemLanguageResultExecution timeMemory
340647tengiz05Bank (IZhO14_bank)C++17
100 / 100
221 ms8300 KiB
#include <bits/stdc++.h> using namespace std; #define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); #define all(x) (x).begin(), (x).end() #define pb push_back #define pii pair<int, int> #define ff first #define ss second #define PI acos(-1) #define ld long double template<class T> bool chmin(T& a, const T& b) {return a>b? a=b, true:false;} template<class T> bool chmax(T& a, const T& b) {return a<b? a=b, true:false;} const int mod = 1e9+7, N = 2e4+5; int msb(int val){return sizeof(int)*8-__builtin_clzll(val)-1;} int a[N], n, m, k; int b[N]; int pr[N]; vector<int> pos[N]; bool check(int mask, int l, int r){ int sum = pr[r]-pr[l-1]; bool found = false; for(auto x : pos[sum]){ if((mask|x) == mask)found = true; } if(!found)return false; if(l == r)return true; int mid = (l+r)/2; int sum1 = pr[mid] - pr[l-1]; bool ok = false; for(auto x : pos[sum1]){ if((mask|x) == mask)ok |= (check(x, l, mid) && check(mask^x, mid+1, r)); if(ok)return true; } return ok; } void solve(int test_case){ int i, j; cin >> n >> m; for(i=1;i<=n;i++){ cin >> a[i]; pr[i] = a[i] + pr[i-1]; } for(i=0;i<m;i++)cin >> b[i]; for(int mask=0; mask < (1<<m); mask++){ int sum = 0; for(i=0;i<m;i++){ if(mask & (1<<i))sum += b[i]; }pos[sum].pb(mask); } if(check((1<<m)-1, 0,n))cout << "YES\n"; else cout << "NO\n"; return; } signed main(){ FASTIO; #define MULTITEST 0 #if MULTITEST int _T; cin >> _T; for(int T_CASE = 1; T_CASE <= _T; T_CASE++) solve(T_CASE); #else solve(1); #endif return 0; }

Compilation message (stderr)

bank.cpp: In function 'void solve(int)':
bank.cpp:37:9: warning: unused variable 'j' [-Wunused-variable]
   37 |  int i, j;
      |         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...