Submission #1001732

#TimeUsernameProblemLanguageResultExecution timeMemory
1001732kh0iBank (IZhO14_bank)C++17
100 / 100
85 ms8624 KiB
#include "bits/stdc++.h" using namespace std; #ifdef LOCAL #include "debug.h" #else #define debug(...) #endif using ll = long long; using pii = pair<int, int>; #define F first #define S second #define sz(x) (int)((x).size()) #define all(x) (x).begin(), (x).end() mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll get_rand(ll l, ll r) { assert(l <= r); return uniform_int_distribution<ll> (l, r)(rng); } const int N = 20; int n, m, a[N], b[N]; int f[1 << N], r[1 << N]; void solve(){ cin >> n >> m; for(int i = 0; i < n; ++i) cin >> a[i]; for(int i = 0; i < m; ++i) cin >> b[i]; memset(f, -1, sizeof(f)); f[0] = r[0] = 0; for(int mask = 1; mask < (1 << m); ++mask){ for(int last = 0; last < m; ++last){ if(!(mask & (1 << last))) continue; int pre = mask ^ (1 << last); if(f[pre] == -1) continue; int nx = f[pre]; int amt = b[last] + r[pre]; if(amt < a[nx]){ f[mask] = nx; r[mask] = amt; } else if(amt == a[nx]){ f[mask] = nx + 1; r[mask] = 0; } } if(f[mask] == n){ cout << "YES"; return; } } cout << "NO"; } int32_t main() { cin.tie(nullptr)->sync_with_stdio(0); #define task "troll" if(fopen(task".inp", "r")){ freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } int test = 1; // cin >> test; for(int i = 1; i <= test; ++i){ // cout << "Case #" << i << ": "; solve(); } #ifdef LOCAL cerr << "\n[Time]: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms.\n"; #endif return 0; }

Compilation message (stderr)

bank.cpp: In function 'int32_t main()':
bank.cpp:72:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:73:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...