제출 #437407

#제출 시각아이디문제언어결과실행 시간메모리
437407Atlant은행 (IZhO14_bank)C++14
100 / 100
140 ms8632 KiB
#include <bits/stdc++.h> using namespace std; //#define int long long #define dem(x) __builtin_popcount(x) #define endl '\n' #define pb push_back #define SZ(x) (int)((x).size()) #define fi first #define se second typedef pair<int,int> ii; typedef long long ll; const ll mod = 1e9 + 7; //998244353 signed main() { ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0); // freopen("c.inp","r",stdin); int n, m; cin >> n >> m; vector<int> a(n); vector<int> b(m), dp(1<<m,-1), have(1<<m, -1); for(int &i : a)cin >> i; for(int &i : b)cin >> i; dp[0] = have[0] = 0; for(int mask = 1;mask < 1 << m;++mask){ for(int i = 0;i < m;++i)if(mask&(1<<i)){ int tt = mask - (1 << i); if(dp[tt] == -1)continue; int Next = have[tt] + b[i]; int target = a[dp[tt]]; if(Next < target){ dp[mask] = dp[tt]; have[mask] = Next; } else if(Next == target){ dp[mask] = dp[tt] + 1; have[mask] = 0; } } if(dp[mask] == n){ cout << "YES"; return 0; } } cout << "NO"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...