이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#ifdef LOCAL
#include "D:\debug.h"
#else
#define cebug(...) "Orz_chUoNgnn"
#endif
using namespace std;
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ii pair<int, int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>
#define cd complex<double>
const ll mod = 1e9 + 7;
const ll INF = 1e18L + 5;
const double PI = acos(-1);
const int block = 320;
const int N = 20;
int tc, tt = 1;
int n, m;
int a[N + 5], b[N + 5], ps[N + 5];
vi f[N + 5];
bool dp[N + 5][(1<<N) + 5];
ll cal(int j) {
ll sum = 0;
for(int k=0; k<m; k++)
if(1 & (j>>k)) sum += b[k + 1];
return sum;
}
void solve() {
cin>>n>>m;
for(int i=1; i<=n; i++) {
cin>>a[i];
ps[i] = ps[i - 1] + a[i];
}
for(int i=1; i<=m; i++) cin>>b[i];
for(int i=1; i<=n; i++) {
for(int j=0; j<(1<<m); j++)
if(cal(j) == a[i]) f[i].pb(j);
}
dp[0][0] = true;
for(int i=1; i<=n; i++) {
for(int j=0; j<(1<<m); j++) {
if(cal(j) != ps[i]) continue;
for(auto x: f[i])
if((j & x) == x)
dp[i][j] |= dp[i - 1][j xor x];
if(dp[n][j]) {
cout<<"YES";
return;
}
}
}
cout<<"NO";
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
// freopen(".INP", "r", stdin);
// freopen(".OUT", "w", stdout);
for(int tc=1; tc<=tt; tc++) solve();
cerr<<"\nTime elapsed: "<<1000.0*clock()/CLOCKS_PER_SEC<<" ms.\n";
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... |