Submission #1090908

#TimeUsernameProblemLanguageResultExecution timeMemory
1090908StillOnQiCondensationBank (IZhO14_bank)C++14
100 / 100
112 ms8908 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; #define all(x) (x).begin(), (x).end() #define inf 1000000007ll #define llmax LLONG_MAX #define pi 3.141592653589793238462643383279502884197169399 long long binpow(long long a, long long b) { long long res = 1; while (b > 0) { if (b & 1) res = res * a; a = a * a; b >>= 1; } return res; } ll ncr(int n, int r) { if (n < r) return 0; long long p = 1, k = 1; if (n - r < r) r = n - r; if (r != 0) { while (r) { p *= n; k *= r; long long m = __gcd(p, k); p /= m; k /= m; n--; r--; } } else p = 1; return p; } vector <ll> vcreate(int n){ vector <ll> v(n); for (int i = 0; i < n; i++) { cin>>v[i]; } return v; } int dx[4]{1, -1, 0, 0}, dy[4]{0, 0, 1, -1}; ll ModExp(ll x, ll n, ll m) { assert(n >= 0); x %= m; // note: m * m must be less than 2^63 to avoid ll overflow ll res = 1; while (n > 0) { if (n % 2 == 1) { res = res * x % m; } x = x * x % m; n /= 2; } return res; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); /* freopen("movie.in", "r", stdin); freopen("movie.out", "w", stdout); */ /* ll T; cin>>T; for(ll oo=0; oo<T; oo++) { } */ int n{},m{}; cin>>n>>m; vi v(n); vi cash(m); for(int i{0}; i<n; i++)cin>>v[i]; for(int i{0}; i<m; i++)cin>>cash[i]; vector<pair<int,int>> dp(1<<m,{0,0}); bool ans{false}; for(int s{0}; s<(1<<m); s++) { for(int j{0}; j<m; j++) { if((s&(1<<j))==0)continue; if(dp[s].first==n)continue; pair<int,int> curr=dp[s^(1<<j)]; if(curr.second+cash[j]==v[curr.first]) { curr.first++; curr.second=0; dp[s]=max(dp[s],curr); } else if(curr.second+cash[j]<v[curr.first]) { curr.second+=cash[j]; dp[s]=max(dp[s],curr); } } if(dp[s].first==n)ans=true; } if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...