Submission #397898

#TimeUsernameProblemLanguageResultExecution timeMemory
397898haskaranBank (IZhO14_bank)C++17
19 / 100
100 ms16724 KiB
#include <bits/stdc++.h> using namespace std; const int N = 21; int n, m, a[N + 5], b[N + 5], ps[N + 5], dp[(1 << N) + 10], sm[(1 << N) + 10]; bool ans; int main() { ios:: sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); cin >> n >> m; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= m; i++) cin >> b[i]; for (int i = 1; i <= n; i++) ps[i] = a[i] + ps[i - 1]; for (int i = 1; i <= m; i++) for (int msk = 0; msk < 1 << m + 1; msk++) if (msk >> i & 1) { sm[msk] = sm[msk ^ (1 << i)] + b[i]; bool flag = (dp[msk ^ (1 << i)] < n && sm[msk] - ps[dp[msk ^ (1 << i)]] == a[dp[msk ^ (1 << i)] + 1]); dp[msk] = max(dp[msk], dp[msk ^ (1 << i)] + flag); ans |= dp[msk] == n; } cout << (ans? "YES\n": "NO\n"); }

Compilation message (stderr)

bank.cpp: In function 'int main()':
bank.cpp:19:40: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   19 |         for (int msk = 0; msk < 1 << m + 1; msk++)
      |                                      ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...