이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define TASK "file"
#define all(x) x.begin(), x.end()
#define MASK(x) (1LL << (x))
#define BIT(x, i) (((x) >> (i)) & 1)
using namespace std;
const int N = 2e5 + 7;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const long long INFLL = 1e18 + 7;
typedef long long ll;
typedef long double ld;
template <class X, class Y> bool minimize(X &a, Y b) {
if (a > b) return a = b, true;
return false;
}
template <class X, class Y> bool maximize(X &a, Y b) {
if (a < b) return a = b, true;
return false;
}
int n, m;
int bank[22];
int salary[22];
int dp[1 << 20];
int remain[1 << 20];
void solve(void) {
cin >> n >> m;
for (int i = 0; i < n; i ++) cin >> salary[i];
for (int i = 0; i < m; i ++) cin >> bank[i];
memset(dp, -1, sizeof dp);
dp[0] = 0;
for (int mask = 0; mask < 1 << m; mask ++) {
for (int i = 0; i < m ; i ++) if (BIT(mask, i)) {
int nmask = mask ^ MASK(i);
if (dp[nmask] < 0) continue;
if (remain[nmask] + bank[i] < salary[dp[nmask]]) {
dp[mask] = dp[nmask];
remain[mask] = remain[nmask] + bank[i];
} else
if (remain[nmask] + bank[i] == salary[dp[nmask]]) {
dp[mask] = dp[nmask] + 1;
remain[mask] = 0;
}
if (dp[mask] == n)
return void (cout << "YES");
}
}
cout <<"NO";
}
int main(void) {
ios_base::sync_with_stdio(0);
cin.tie(0);
int test = 1;
// cin >> test;
while (test --) {
solve();
}
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... |