이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define sz(x) (int)x.size()
#define F first
#define S second
#define int long long
const int dx[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int dy[] = {1, 0, -1, 0, -1, 1, -1, 1};
const int maxn = 21;
const int N = 2e5+7;
const int inf = 1e18;
const int mod = 1e9+7;
using namespace std;
int n, m;
int a[maxn], b[maxn];
pair<int, int> dp[(1ll << maxn)];
void solve(){
cin >> n >> m;
for(int i = 0; i < n; i++) cin >> a[i];
for(int i = 0; i < m; i++) cin >> b[i];
for(int mask = 1; mask < (1 << m); mask++){
for(int i = 0; i < m; i++){
if((mask & (1 << i)) == 0){
if(dp[mask].S + b[i] == a[dp[mask].F]){
dp[(mask | (1 << i))] = {dp[mask].F + 1, 0};
}else if(dp[mask].S + b[i] < a[dp[mask].F]){
dp[(mask | (1 << i))] = {dp[mask].F, dp[mask].S + b[i]};
}
}
}
}
for(int mask = 1; mask < (1 << m); mask++){
if(dp[mask].F == n){
cout << "YES\n";
return;
}
}
cout << "NO\n";
}
signed main(){
speed
int test = 1;
// cin >> test;
while(test--){
solve();
}
}
| # | 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... |