이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |