| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1287096 | tkvinhtruongquang | 은행 (IZhO14_bank) | C++20 | 97 ms | 8652 KiB |
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define clz __builtin_clz
#define popcount __builtin_popcount
#define lb(x) lower_bound(x)
#define ub(x) upper_bound(x)
#define loop(i, j, n, k) for(int i = j; i <= n; i += k)
#define fast ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
template <typename T>
inline void print(T x) { cerr << x << endl; }
template <typename T>
inline void print(vector <T> x) { cerr << '['; loop(i, 0, sz(x) - 2, 1) cerr << x[i] << ", "; cerr << x.back() << ']' << endl; }
template <typename T>
inline bool maximize(T &a, const T &b) { return a < b ? (a = b) : 0; }
template <typename T>
inline bool minimize(T &a, const T &b) { return a > b ? (a = b) : 0; }
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
using pss = pair<string, string>;
using vll = vector<ll>;
using pll = pair<ll, ll>;
#define debug(x) cerr << #x << " = "; print(x)
mt19937 rng(chrono :: steady_clock :: now().time_since_epoch().count());
template <typename T>
inline int rand_range(T l, T r) { return uniform_int_distribution<T> (l, r)(rng); }
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
freopen("error.txt", "w", stderr);
}
int main() {
// setIO("task");
fast;
int n, m; cin >> n >> m;
vi arr(n); for(auto &i : arr) cin >> i;
vi brr(m); for(auto &i : brr) cin >> i;
vi people_covered((1 << m), -1);
vi left_over((1 << m));
people_covered[0] = 0;
loop(mask, 1, (1 << m) - 1, 1) {
loop(j, 0, m - 1, 1) {
if(mask & (1 << j)) {
int prev = mask ^ (1 << j);
if(people_covered[prev] == -1) continue;
int cur_budget = left_over[prev] + brr[j];
int salary = arr[people_covered[prev]];
if(cur_budget < salary) {
people_covered[mask] = people_covered[prev];
left_over[mask] = cur_budget;
} else if(cur_budget == salary) {
people_covered[mask] = people_covered[prev] + 1;
// we have used all the money.
left_over[mask] = 0;
}
}
}
if(people_covered[mask] == n) {
cout << "YES\n";
return 0;
}
}
cout << "NO\n";
}
컴파일 시 표준 에러 (stderr) 메시지
| # | 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... | ||||
