Submission #1105298

#TimeUsernameProblemLanguageResultExecution timeMemory
1105298khoile25108Bank (IZhO14_bank)C++14
0 / 100
1 ms592 KiB
#include <bits/stdc++.h> using namespace std; #define faster ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define FOR(i,a,b) for(int i = a; i <= b; i++) #define FOD(i,a,b) for(int i = a; i >= b; i--) #define fi first #define se second #define pb push_back #define ll long long #define ull unsigned long long #define lcm(a,b) (a*b)/__gcd(a,b) #define ii pair<int,int> #define iii pair<int,pair<int,int>> #define iv pair<pair<int,int>,pair<int,int>> const int inf = 1e9; const ll INF = 1e18; const int mod = 1e9 + 7; const int N = 20; const int dx[] = {-1,0,1,0}; const int dy[] = {0,1,0,-1}; const int dxx[] = {-1,-1,0,1,1,1,0,-1}; const int dyy[] = {0,1,1,1,0,-1,-1,-1}; int n, m; ii dp[(1 << N) + 105]; int a[N], b[N]; void solve() { for(int mask = 0; mask < (1 << m); mask++) dp[mask] = {-1,-1}; dp[0] = {0,0}; for(int mask = 0; mask < (1 << m); mask++) { for(int i = 0; i < n; i++) { if((mask >> i) & 1 && dp[mask^(1<<i)].fi != -1) { int submask = mask ^ (1 << i); int cur = dp[submask].se + b[i]; int tar = a[dp[mask].fi]; if(tar > cur) dp[mask] = {dp[mask].fi, cur}; else if(tar == cur) dp[mask] = {dp[mask].fi + 1, 0}; } } if(dp[mask].fi == n - 1) { cout << "YES\n"; return; } } cout << "NO\n"; } void input() { //freopen("TEST.INP", "r", stdin); //freopen("TEST.OUT", "w", stdout); cin >> n >> m; for(int i = 0; i < n; i++) cin >> a[i]; for(int i = 0; i < m; i++) cin >> b[i]; } signed main() { faster input(); 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...