Submission #1086305

#TimeUsernameProblemLanguageResultExecution timeMemory
1086305TrinhKhanhDungBank (IZhO14_bank)C++14
100 / 100
75 ms8784 KiB
#include <bits/stdc++.h> #define ll long long #define fi first #define se second #define sz(x) (int)x.size() #define ALL(v) v.begin(),v.end() #define MASK(k) (1LL << (k)) #define BIT(x, i) (((x) >> (i)) & 1) #define oo (ll)1e18 #define INF (ll)1e9 #define MOD (ll)(998244353) using namespace std; template<class T1, class T2> bool maximize(T1 &a, T2 b){if(a < b){a = b; return true;} return false;} template<class T1, class T2> bool minimize(T1 &a, T2 b){if(a > b){a = b; return true;} return false;} template<class T1, class T2> void add(T1 &a, T2 b){a += b; if(a >= MOD) a -= MOD;} template<class T1, class T2> void sub(T1 &a, T2 b){a -= b; if(a < 0) a += MOD;} template<class T> void cps(T &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());} const int MAX = 20; int N, M; int a[MAX + 10], b[MAX + 10], l[MASK(MAX) + 10], f[MASK(MAX) + 10]; void solve(){ cin >> N >> M; for(int i=0; i<N; i++){ cin >> a[i]; } for(int i=0; i<M; i++){ cin >> b[i]; } memset(f, -1, sizeof f); f[0] = 0; for(int mask=0; mask<MASK(M); mask++) if(f[mask] != -1){ for(int i=0; i<M; i++) if(!BIT(mask, i)){ int x = b[i] + l[mask]; if(x < a[f[mask]]){ f[mask | MASK(i)] = f[mask]; l[mask | MASK(i)] = x; } else if(x == a[f[mask]]){ f[mask | MASK(i)] = f[mask] + 1; l[mask | MASK(i)] = 0; } if(f[mask | MASK(i)] == N){ cout << "YES\n"; return; } } } cout << "NO\n"; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); // freopen("numtable.inp","r",stdin); // freopen("numtable.out","w",stdout); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...