이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n, m;
cin >> n >> m;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++) cin >> a[i];
vector<int> b(m);
for (auto &i : b) cin >> i;
vector<vector<bool>> dp(n + 1, vector<bool>(1<<m));
for (int j = 0; j < 1<<m; j++) dp[0][j] = true;
for (int j = 0; j < 1<<m; j++) {
int sm = 0, x = j;
while (x) {
sm += b[x & -x];
x -= (x & -x);
}
// for (int i = 0; i < m; i++) {
// if ((j>>i) & 1) sm += b[i];
// }
int p = 0;
for (int i = 1; i <= n; i++) {
p += a[i];
if (sm == p) dp[i][j] = dp[i - 1][j];
for (int k = 0; k < m && !dp[i][j]; k++) {
if (((j>>k) & 1)) dp[i][j] = dp[i][j - (1<<k)];
}
// int x = j;
// while (x && !dp[i][j]) {
// dp[i][j] = dp[i][j - (x & -x)];
// x -= (x & -x);
// }
}
}
cout << (count(dp[n].begin(), dp[n].end(), true) ? "YES" : "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... |