Submission #935933

#TimeUsernameProblemLanguageResultExecution timeMemory
935933Youssif_ElkadiBank (IZhO14_bank)C++17
0 / 100
91 ms176132 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int N = 1e3 + 5, inf = 1e9, mod = 1e9 + 7; int n, m; int dp[21][(1 << 20)]; vector<int> musks[N]; vector<int> people, cash; bool solve(int ind, int musk) { if (ind == n) return 1; if (~dp[ind][musk]) return dp[ind][musk]; bool ret = 0; for (auto v : musks[people[ind]]) { if (musk & v) continue; ret |= solve(ind + 1, (musk | v)); } return dp[ind][musk] = ret; } int main() { ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); memset(dp, -1, sizeof dp); cin >> n >> m; people.resize(n), cash.resize(m); for (int i = 0; i < n; i++) cin >> people[i]; for (int i = 0; i < m; i++) cin >> cash[i]; for (int i = 0, sum = 0; i < (1 << m); musks[sum].push_back(i), sum = 0, dp[n][i] = 1, i++) for (int j = 0; j < m; j++) if (i & (1 << j)) sum += cash[j]; cout << (solve(0, 0) ? "YES\n" : "NO\n"); // for (int i = n - 1; i >= 0; i--) // for (int j = 0; j < (1 << m); j++) // for (auto &v : musks[people[i]]) // if ((j & v) == 0) // dp[i][j] |= dp[i + 1][j | v]; // cout << (dp[0][0] ? "YES\n" : "NO\n"); } /* YES */

Compilation message (stderr)

bank.cpp: In function 'bool solve(int, int)':
bank.cpp:22:26: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   22 |     return dp[ind][musk] = ret;
      |            ~~~~~~~~~~~~~~^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...