제출 #996716

#제출 시각아이디문제언어결과실행 시간메모리
996716Vietnow은행 (IZhO14_bank)C++17
100 / 100
160 ms14556 KiB
#include <bits/stdc++.h> #define yes cout<<"YES\n" #define no cout<<"NO\n" #define int long long #define ff first #define ss second #define pb push_back #define dd double #define tm zildjian using namespace std; const int N = 21; const int INF = 1e18; const int mod = 1e9+7; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); // int binpow (int a, int n) { // if (n == 0) // return 1; // if (n % 2 == 1) // return (binpow (a, n-1)%mod * a%mod)%mod; // else { // int b = binpow (a, n/2) % mod; // return (b%mod * b%mod)%mod; // } // } int n,m; vector<int> mask[N]; int a[N],b[N]; bool was[N][1<<N]; void dfs(int i, int curr_mask){ if(i == n+1){ yes; exit(0); } if(was[i][curr_mask]) return; was[i][curr_mask] = 1; for(auto to:mask[i]){ if(curr_mask&to) continue; dfs(i+1,curr_mask|to); } } void solve(){ cin>>n>>m; for(int i = 1;i<=n;i++) cin>>a[i]; for(int i = 1;i<=m;i++) cin>>b[i]; for(int msk = 0;msk<(1<<m);msk++){ int sum = 0; for(int i = 0;i<m;i++){ if(msk&(1<<i)) sum+=b[i+1]; } for(int i = 1;i<=n;i++){ if(a[i] == sum) mask[i].pb(msk); } } dfs(1,0); no; } signed main(){ // freopen("search.in","r",stdin); // freopen("search.out","w",stdout); ios_base::sync_with_stdio(0); cin.tie(nullptr); // cout.tie(nullptr); int t = 1; // cin>>t; for(int i = 1;i<=t;i++){ // cout<<"Case "<<i<<": "; 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...