이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("O3")
#pragma GCC target("avx,avx2,sse4")
#include <bits/stdc++.h>
using namespace std;
signed main() {
// clock_t start = clock();
int n, m;cin>>n>>m;
vector<int> a(n);
for (int &x:a)cin>>x;
vector<int> b(m);
for (int &x:b)cin>>x;
sort(a.begin(), a.end());
sort(b.begin(), b.end());
vector<vector<int>> bitmasks;
for (int i=0;i<n;i++) {
vector<int> btm;
int x = a[i];
int mx = (1 << m);
for (int j=1;j<mx;j++) {
int sm = 0, cp = j;
int cnt=0;
while (cp) {
if ((cp & 1) == 1) {
sm += b[m-cnt-1];
if (sm > x) break;
}
cnt++;
cp >>= 1;
}
if (sm == x) {
btm.push_back(j);
}
}
if (btm.size() == 0) {
cout << "NO\n";
return 0;
}
bitmasks.push_back(btm);
}
vector<int> ger;
for (int x:bitmasks[0]) {
ger.push_back(x);
}
for (int i=1;i<n;i++) {
vector<int> copy;
for (int x:bitmasks[i]) {
for (int y:ger) {
if ((x & y) == 0) {
copy.push_back((x | y));
}
}
}
ger = copy;
}
if (ger.size()) {
cout << "YES\n";
}
else {
cout << "NO\n";
}
// clock_t end = clock();
// double dif = ((double)end - (double)start) / CLOCKS_PER_SEC;
// cout << dif << "\n";
}
# | 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... |