이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for(ll i = (ll)a; i <= (ll)b; i++)
#define DEC(i, a, b) for(ll i = (ll)a; i >= (ll)b; i--)
typedef pair<ll, ll> pi;
typedef pair<pi, ll> pii;
typedef pair<ll, pi> ipi;
typedef pair<pi, pi> pipi;
#define mp make_pair
#define f first
#define s second
typedef vector<ll> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define size(v) (ll) v.size()
#define disc(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
#define memset(x, v) memset(x, v, sizeof x)
#define INF (const ll) (1e9 + 100)
#define LLINF (const ll) 1e18
#define mod (const ll) (1e9 + 7)
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sandybridge __attribute__((optimize("Ofast"), target("arch=sandybridge")))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //can be used by calling rng() or shuffle(A, A+n, rng)
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusive
/*
Serve the people in order.
However, need to loop by bitmask so order of notes is variable.
cur[bm] = first index of person not served, extra[bm] = leftover total value of notes not used to serve ppl
bm stores which notes we take.
*/
ll n, m, a[25], b[25], cur[(1<<20)], extra[(1<<20)];
int main() {
fastio; cin >> n >> m;
FOR(i, 0, n-1) cin >> a[i];
FOR(i, 0, m-1) cin >> b[i];
memset(cur, -1);
memset(extra, -1);
cur[0] = extra[0] = 0;
FOR(bm, 0, (1<<m)-1) {
FOR(note, 0, m-1) {
if (!(bm & (1<<note))) continue;
ll prebm = bm ^ (1<<note);
if (cur[prebm] == -1) continue;
else if (extra[prebm] + b[note] == a[cur[prebm]]) {
cur[bm] = cur[prebm] + 1;
extra[bm] = 0;
} else if (extra[prebm] + b[note] < a[cur[prebm]]) {
cur[bm] = cur[prebm];
extra[bm] = extra[prebm] + b[note];
}
// if extra + current node > current person to serve, this bitmask is impossible alr, ignore
}
if (cur[bm] == n) return cout << "YES", 0;
}
cout << "NO";
}
# | 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... |