이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define se second
const int oo = 1e18;
const int maxn = 1e5 + 10;
bool dp[23][1<<20];
int s[1<<20];
vector<int> f[23];
void solve(){
int n, m;
cin >> n >> m;
vector<int> a(n + 1), b(m);
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 0; i < m; i++) cin >> b[i];
for(int j = 0; j < (1<<m); j++){
int sum = 0;
for(int i = 0; i < m; i++){
if(j&(1<<i)) sum+=b[i];
}
s[j] = sum;
}
for(int i = 1; i <= n; i++){
for(int j = 0; j < (1<<m); j++){
if(s[j] == a[i]){
f[i].pb(j);
}
}
}
memset(dp,0, sizeof(dp));
dp[0][0] = 1;
bool c = 0;
long long pf = 0;
for(int i = 1; i <= n; i++){
pf += a[i];
for(int j = 0; j < (1<<m); j++){
if(s[j] != pf) continue;
for(auto x: f[i]) if((x&j)==x)dp[i][j] |= dp[i - 1][j ^ x];
if(i == n && dp[i][j]){
c = 1; break;
}
}
}
if(c) cout<<"YES";
else cout<<"NO";
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
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... |