제출 #948820

#제출 시각아이디문제언어결과실행 시간메모리
948820tnknguyen_은행 (IZhO14_bank)C++14
46 / 100
3 ms20828 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define endl '\n' #define MASK(k) (1LL<<k) int n, m; int a[30], b[30]; // ------------ SUBTASKS ------------ namespace SUB1{ bool ok(){ return (n == 1); } void solve(){ vector<int> f(1e3+5, 0); f[0] = 1; for(int i=1; i<=m; ++i){ for(int j=a[1]; j>=b[i]; --j){ f[j] |= f[j - b[i]]; } } cout<<(f[a[1]] ? "YES" : "NO"); //----------------------------- exit(0); } } vector<int> v[21]; int f[21][MASK(21)]; namespace SUB2{ void solve(){ for(int i=0; i<MASK(m); ++i){ int sum = 0; for(int j=i; j!=0; j-=(j&-j)){ sum += b[__lg((j&-j)) + 1]; } for(int j=1; j<=n; ++j){ if(a[j] == sum){ v[j].push_back(i); } } } v[0].push_back(0); int fl = 1; for(int i=1; i<=n; ++i){ int b = 0; for(int x : v[i]){ for(int y : v[i-1]){ if((x & y) == 0){ f[i][x | y] = 1; b = 1; } } } if(!b){ fl = 0; break; } } cout<<(fl ? "YES" : "NO"); //----------------------------- exit(0); } } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("main.inp","r",stdin); // freopen("main.out","w",stdout); //f[mask][i] = cin>>n>>m; for(int i=1; i<=n; ++i){ cin>>a[i]; } for(int j=1; j<=m; ++j){ cin>>b[j]; } if(SUB1::ok()){ SUB1::solve(); } SUB2::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...