Submission #887774

#TimeUsernameProblemLanguageResultExecution timeMemory
887774duckindogBank (IZhO14_bank)C++14
100 / 100
91 ms8652 KiB
//from duckindog wth depression #include<bits/stdc++.h> using namespace std; const int N = 21, M = (1 << 20); int a[N], b[N]; pair<int, int> f[M]; int32_t main() { cin.tie()->sync_with_stdio(0); if (fopen("duck.inp", "r")) { freopen("duck.inp", "r", stdin); freopen("duck.out", "w", stdout); } int n, m; cin >> n >> m; for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 1; i <= m; ++i) cin >> b[i]; f[0] = {1, 0}; for (int mask = 1; mask <= (1 << m) - 1; ++mask) { for (int i = 1; i <= m; ++i) { if (!((mask >> i - 1) & 1)) continue; int j, t; tie(j, t) = f[mask & ~(1 << i - 1)]; if (t + b[i] > a[j]) continue; int nj = (t + b[i] == a[j] ? j + 1 : j); int nt = (nj > j ? 0 : t + b[i]); f[mask] = max(f[mask], {nj, nt}); } if (f[mask].first > n) { cout << "YES"; return 0; } } cout << "NO"; }

Compilation message (stderr)

bank.cpp: In function 'int32_t main()':
bank.cpp:26:24: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   26 |       if (!((mask >> i - 1) & 1)) continue;
      |                      ~~^~~
bank.cpp:27:47: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   27 |       int j, t; tie(j, t) = f[mask & ~(1 << i - 1)];
      |                                             ~~^~~
bank.cpp:15:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     freopen("duck.inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:16:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     freopen("duck.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...