이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007LL
int N, M;
int a[20], b[20];
pair<int, int> dp[1<<20];
int main() {
//freopen("feast.in", "r", stdin);
//freopen("feast.out", "w", stdout);
//ios_base::sync_with_stdio(false);
//cin.tie(0);
cin >> N >> M;
for (int i = 0; i < N; i++) cin >> a[i];
for (int i = 0; i < M; i++) cin >> b[i];
dp[0] = {0, 0};
for (int bm = 1; bm < (1 << M); bm++) {
dp[bm] = {0, 0};
for (int i = 0; i < M; i++) {
if (bm & (1<<i)) {
int nbm = bm^(1<<i);
pair<int, int> pp = dp[nbm];
if (pp.second + b[i] < a[pp.first]) {
// cout << "add " << b[i] << " to " << pp.second << " (a[pp.first] = " << a[pp.first] << ")\n";
pp.second += b[i];
}
else if (pp.second+b[i] == a[pp.first]) {
// cout << "add " << b[i] << " to " << pp.second << " (a[pp.first] = " << a[pp.first] << ")\n";
pp.first++, pp.second = 0;
}
if (dp[bm] < pp) {
// cout << dp[bm].first << " " << dp[bm].second << "\n";
// cout << pp.first << " " << pp.second << "\n\n";
}
if (dp[bm].first < pp.first || dp[bm].second == 0) dp[bm] = max(dp[bm], pp);
// if (dp[bm] < pp) cout << "Life is a lie\n";
if (pp.first == N) {
cout << "YES" << endl;
return 0;
}
//cout << bitset<5>(nbm) << " : " << bitset<5>(bm) << " - " << pp.first << " " << pp.second << endl;
}
}
}
cout << "NO" << endl;
}
# | 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... |