이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i < n; i++)
#define ull unsigned long long
#define ll long long
#define SPEED \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
using namespace std;
const int N = 4e5 + 13;
const int maxa = 2e5 + 13;
const ll mod = 1e9 + 7;
using tp = tuple<ll, ll, ll>;
const int mxn = 30;
void prestart() {}
void start()
{
int n, m;
cin >> n >> m;
int a[n], b[m];
forn(i, n) cin >> a[i];
forn(i, m) cin >> b[i];
int covered[(1 << m)];
int left[(1 << m)];
fill(covered, covered + (1 << m), -1);
fill(left, left + (1 << m), -1);
covered[0] = 0;
left[0] = 0;
for(int s = 0; s < (1 << m); s++) {
for(int i = 0; i < m; i++) {
if (s & (1 << i) == 0) continue;
int prev = s ^ (1 << i);
if (covered[prev] == -1) continue;
if (a[covered[prev]] > left[prev] + b[i]) {
covered[s] = covered[prev];
left[s] = left[prev] + b[i];
}
else if (left[prev] + b[i] == a[covered[prev]]) {
covered[s] = covered[prev] + 1;
left[s] = 0;
}
}
}
for(int s = 0; s < (1 << m); s++) {
if (covered[s] == n) {
cout << "Yes" << "\n";
return;
}
}
cout << "No" << "\n";
}
signed main()
{
SPEED;
int t = 1;
prestart();
// cin >> t;
while (t--)
{
start();
}
}
컴파일 시 표준 에러 (stderr) 메시지
bank.cpp: In function 'void start()':
bank.cpp:39:30: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
39 | if (s & (1 << i) == 0) continue;
| ~~~~~~~~~^~~~
# | 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... |