Submission #819856

#TimeUsernameProblemLanguageResultExecution timeMemory
819856kanishk2606Bank (IZhO14_bank)C++17
25 / 100
1084 ms172580 KiB
// uggjaa ped #include <bits/stdc++.h> using namespace std; #define ll long long #define loop(lcv, lower, upper) for (ll lcv = lower; lcv < upper; lcv++) bool help(vector<vector<ll>> dp, ll i, ll mask, ll a[], ll left, ll b[], ll m, ll n) { if (mask == 0) return false; if (dp[i][mask] != -1) return dp[i][mask]; bool ans = false; loop(j, 0, m) { if (((1 << j) & mask)) { if (left == b[j]) { if (i == n - 1) return dp[i][mask] = true; ans = ans or help(dp, i + 1, mask ^ (1 << j), a, a[i + 1], b, m, n); } else if (left > b[j]) { ans = ans or help(dp, i, mask ^ (1 << j), a, left - b[j], b, m, n); } } } return dp[i][mask] = ans; } void solve() { ll n, m; cin >> n >> m; ll a[n], b[m]; loop(i, 0, n) cin >> a[i]; loop(i, 0, m) cin >> b[i]; vector<vector<ll>> dp(n, vector<ll>(1 << m, -1)); cout << (help(dp, 0, (1 << m) - 1, a, a[0], b, m, n) ? "YES" : "NO") << endl; } int main() { solve(); return 0; }

Compilation message (stderr)

bank.cpp: In function 'bool help(std::vector<std::vector<long long int> >, long long int, long long int, long long int*, long long int, long long int*, long long int, long long int)':
bank.cpp:22:40: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   22 |                     return dp[i][mask] = true;
bank.cpp:31:24: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   31 |     return dp[i][mask] = ans;
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...