Submission #809841

#TimeUsernameProblemLanguageResultExecution timeMemory
809841fanwenBank (IZhO14_bank)C++17
100 / 100
104 ms8516 KiB
#include <bits/stdc++.h> using namespace std; #define MASK(x) (1LL << (x)) #define BIT(x, i) (((x) >> (i)) & 1) #define ALL(x) (x).begin(), (x).end() #define REP(i, n) for (int i = 0, _n = n; i < _n; ++i) #define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i) #define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i) #define FORE(i, a, b) for (int i = (a), _b = (b); i < _b; ++i) #define debug(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); } template <class A, class B> bool minimize(A &a, B b) { if (a > b) { a = b; return true; } return false; } template <class A, class B> bool maximize(A &a, B b) { if (a < b) { a = b; return true; } return false; } int N, M, a[20], b[20], rem[MASK(20)], dp[MASK(20)]; void you_make_it(void) { cin >> N >> M; REP(i, N) cin >> a[i]; REP(i, M) cin >> b[i]; memset(dp, -1, sizeof dp); dp[0] = 0; REP(mask, MASK(M)) REP(i, M) if(BIT(mask, i)) { if(dp[mask ^ MASK(i)] == -1) continue; int cur = a[dp[mask ^ MASK(i)]], r = rem[mask ^ MASK(i)]; if(r + b[i] < cur) { dp[mask] = dp[mask ^ MASK(i)]; rem[mask] = r + b[i]; } else if(r + b[i] == cur) { dp[mask] = dp[mask ^ MASK(i)] + 1; rem[mask] = 0; } if(dp[mask] == N) return void(cout << "YES"); } cout << "NO"; } signed main() { #ifdef LOCAL freopen("TASK.inp", "r", stdin); freopen("TASK.out", "w", stdout); #endif file("bank"); auto start_time = chrono::steady_clock::now(); cin.tie(0), cout.tie(0) -> sync_with_stdio(0); you_make_it(); auto end_time = chrono::steady_clock::now(); cerr << "\nExecution time : " << chrono::duration_cast <chrono::milliseconds> (end_time - start_time).count() << "[ms]" << endl; return (0 ^ 0); } // Dream it. Wish it. Do it.

Compilation message (stderr)

bank.cpp: In function 'int main()':
bank.cpp:13:57: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 | #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:47:4: note: in expansion of macro 'file'
   47 |    file("bank");
      |    ^~~~
bank.cpp:13:90: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 | #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                                                   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:47:4: note: in expansion of macro 'file'
   47 |    file("bank");
      |    ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...