제출 #658873

#제출 시각아이디문제언어결과실행 시간메모리
658873fatzerglingBank (IZhO14_bank)C++14
100 / 100
181 ms12696 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<int,int> point; #define Rd(r) freopen(r, "r", stdin); #define Wt(w) freopen(w, "w", stdout); #define x first #define y second #define INF 1<<30 #define MAXI 20 vector<int> MASK[MAXI]; int dp[1 << MAXI], rem[1 << MAXI], mark[1 << MAXI], y; bool flag = false; string ZiwenZapper(int n, int m, int a[], int b[]) { y = 0; mark[0] = 1; for(int mask = 0; mask < (1 << m); mask++){ for(int i = 0; i < m; i++){ if(mark[mask ^ (1 << i)] and (mask & (1 << i))){ int last = dp[mask ^ (1 << i)]; int curr = rem[mask ^ (1 << i)] + b[i]; if(curr > a[last]) continue; dp[mask] = last + (curr == a[last] ? 1 : 0); rem[mask] = (curr == a[last] ? 0 : curr); mark[mask] = 1; } } if(dp[mask] == n) y = 1; } return (y ? "YES" : "NO"); } int main() { //Rd("ziwenzapper.in"); int n, m; int a[MAXI], b[MAXI]; cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; for (int j = 0; j < m; j++) cin >> b[j]; string val = ZiwenZapper(n, m, a, b); cout << val << endl; 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...