제출 #37466

#제출 시각아이디문제언어결과실행 시간메모리
37466nickyrio은행 (IZhO14_bank)C++14
100 / 100
393 ms13744 KiB
#include <bits/stdc++.h> #define FOR(i, a, b) for (int i = a; i<= b; ++i) #define FORD(i, a, b) for (int i = a; i>=b; --i) #define REP(i, a) for (int i = 0; i<a; ++i) #define DEBUG(x) { cerr << #x << " = " << x << endl; } #define Arr(A, l, r) { cerr << #A << " = "; FOR(_, l, r) cerr << A[_] << ' '; cerr << endl; } #define N 21 #define pp pair<int, int> #define next __next #define prev __prev #define __builtin_popcount __builtin_popcountll #define bit(S, i) (((S) >> i) & 1) #define IO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define taskname "Test" using namespace std; int n, m, a[N], b[N], dp[1 << N]; vector<int> have[N]; template<class X, class Y> inline void Max(X &x, Y y) { x = x > y ? x : y; } void cal(int mask, int level) { if (level == -1) { return; } cal(mask, level - 1); cal(mask + (1 << level), level - 1); REP(S, 1 << level) { Max(dp[S + mask + (1 << level)], dp[S + mask]); } } int main() { // freopen(taskname".inp","r",stdin); // freopen(taskname".out","w",stdout); IO; cin >> n >> m; FOR(i, 1, n) cin >> a[i]; FOR(i, 2, n) a[i] += a[i - 1]; REP(i, m) cin >> b[i]; REP(S, 1 << m) { int total = 0; REP(i, m) if (bit(S, i)) total += b[i]; FOR(i, 1, n) if (total == a[i]) { have[i].push_back(S); } } memset(dp, 0, sizeof dp); FOR(i, 1, n) { cal(0, m - 1); for (int mask : have[i]) { //cout << i << ' ' << mask << ' ' << dp[mask] << endl; if (dp[mask] == i - 1) { dp[mask] = i; } } } REP(S, 1 << m) { if (dp[S] == 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...