# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1068452 | Aldk | 은행 (IZhO14_bank) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define pb push_back
#define pf push_front
//#define mp make_pair
#define F first
#define S second
#define ff first
#define ss second
#define str string
#define ll long long
#define ull unsigned ll
#define ld long double
#define pll pair<ll,ll>
#define plll pair<ll,pll>
#define pllll pair<pll,pll>
#define pld pair<ld,ld>
#define vl vector<ll>
#define vll vector<pll>
#define vlll vector<plll>
#define vllll vector<pllll>
#define vb vector<bool>
#define sz size()
#define fr front()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bk back();
//#pragma GCC target( "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")
using namespace std;
const ld pi=acos(-1.0);
const ll e5=1e5;
const ll e6=1e6;
const ll e9=1e9;
const ll inf=1e18;
const ll mod=1e9+7;
const ll mod2=998244353;
const ll MOD=106710087877475399;
const ll N=1e3+10;
ll bpm(ll x,ll y,ll m){if(y==0)return 1%m;if(y==1)return x%m;ll p=bpm(x,y/2,m);
if(y%2==0)return p*p%m;else return p*p%m*x%m;}
ll bp(ll x,ll y){if(y==0)return 1;if(y==1)return x;ll p=bp(x,y/2);
if(y%2==0)return p*p;else return p*p*x;}
ll n,m,a[N],b[N];
vl v[N];
bool mp[22][2e6];
void f(ll i,ll x){
if(mp[i][x]) return;
mp[i][x]=1;
if(i==n){
cout<<"YES";
exit(0);
}
for(ll y:v[a[i]]){
if((x&y)==0){
f(i+1,x+y);
}
}
}
void solve(){
cin>>n>>m;
for(ll i=0;i<n;i++) cin>>a[i];
for(ll i=0;i<m;i++) cin>>b[i];
for(ll x=0;x<(1<<m);x++){
ll s=0;
for(ll i=0;i<m;i++){
if((1<<i)&x) s+=b[i];
}
if(s<=1e3) v[s].pb(x);
}
f(0,0);
cout<<"NO";
return;
}
int main(/*Aldk*/){
ios_base::sync_with_stdio(false); cin.tie(NULL);
//freopen("01.in", "r", stdin);
//freopen("01.out ", "w", stdout);
//cout<<setprecision(6)<<fixed;
ll test=1;
//cin>>test;
for(ll i=1;i<=test;i++){
//cout<<"Case "<<i<<":\n";
solve();
//cout<<'\n';
}
return 0;
}