Submission #1287096

#TimeUsernameProblemLanguageResultExecution timeMemory
1287096tkvinhtruongquangBank (IZhO14_bank)C++20
100 / 100
97 ms8652 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"; }

Compilation message (stderr)

bank.cpp: In function 'void setIO(std::string)':
bank.cpp:40:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:41:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:42:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |     freopen("error.txt", "w", stderr);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...