이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// I stand with PALESTINE
//#pragma GCC optimize("Ofast,O3")
//#pragma GCC target("avx,avx2")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
void solve() {
int n, m;
cin >> m >> n;
vector<int> a(n), b(m), cnt(1001);
int diff = 0;
for (int i = 0; i < m; i++) {
cin >> b[i];
diff += !cnt[b[i]];
cnt[b[i]]++;
}
for (int i = 0; i < n; i++) cin >> a[i];
for (int bt = 0; bt < (1 << n); bt++) {
int now = diff, sum = 0;
bool last = (bt & 1) > 0;
for (int i = 0; i < n; i++) {
if ((bt & (1 << i)) > 0 == last) {
sum += a[i];
} else {
if (sum <= 1000) cnt[sum]--;
if (cnt[sum] == 0) now--;
sum = a[i];
last = !last;
}
}
if (now == 0) {
cout << "YES";
return;
}
sum = 0;
last = (bt & 1) > 0;
for (int i = 0; i < n; i++) {
if ((bt & (1 << i)) > 0 == last) {
sum += a[i];
} else {
if (sum <= 1000) cnt[sum]++;
sum = a[i];
last = !last;
}
}
}
cout << "NO";
}
int main() {
cin.tie(0)->sync_with_stdio(false);
#ifdef sunnatov
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int q = 1;
// cin >> q;
while (q--) {
solve();
cout << '\n';
}
}
컴파일 시 표준 에러 (stderr) 메시지
bank.cpp: In function 'void solve()':
bank.cpp:28:33: warning: suggest parentheses around comparison in operand of '==' [-Wparentheses]
28 | if ((bt & (1 << i)) > 0 == last) {
| ~~~~~~~~~~~~~~~~^~~
bank.cpp:45:33: warning: suggest parentheses around comparison in operand of '==' [-Wparentheses]
45 | if ((bt & (1 << i)) > 0 == last) {
| ~~~~~~~~~~~~~~~~^~~
# | 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... |