이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <climits>
#include <algorithm>
using namespace std;
#define speedup ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define ll long long
const int MOD = 1e9+7;
int main(){
speedup
int n, m; cin >> n >> m;
vector<int> a(n), b(m);
for (int i = 0; i < n; i++){
cin >> a[i];
}
for (int i = 0; i < m; i++){
cin >> b[i];
}
pair<int, int> dp[1<<m];
dp[0] = {0, 0};
for (int i = 1; i < (1<<m); i++){
dp[i] = {-1, -1};
for (int j = 0; j < m; j++){
if (i&(1<<j)){
int new_state = i^(1<<j);
if (dp[new_state] == make_pair(-1, -1)){
continue;
}
int left_over = dp[new_state].second+b[j];
int required = a[dp[new_state].first];
if (left_over < required){
if (dp[i].first < dp[new_state].first){
dp[i] = {dp[new_state].first, left_over};
}
}else if (left_over == required){
dp[i] = {dp[new_state].first+1, 0};
}
}
}
if (dp[i].first == n){
cout << "YES" << endl;
return 0;
}
}
cout << "NO" << endl;
return 0;
}
# | 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... |