Submission #1088572

#TimeUsernameProblemLanguageResultExecution timeMemory
1088572vjudge1Bank (IZhO14_bank)C++17
19 / 100
1 ms856 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define _io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define pb push_back #define mp make_pair #define f first #define s second #define vi vector<int> #define vll vector<ll> #define MAX 1e9 int dp[1001][101]; bool used[101]; vi notas; bool solve(int sum, int idx, int m) { if (sum == 0) return true; if (idx >= m || sum < 0) return false; if (dp[sum][idx] != -1) return dp[sum][idx]; bool pegar = false; if (!used[idx] && sum >= notas[idx]) { used[idx] = true; pegar = solve(sum - notas[idx], 0, m); if (!pegar) used[idx] = false; } bool n_pegar = solve(sum, idx + 1, m); return dp[sum][idx] = pegar || n_pegar; } int main() { int n, m; cin >> n >> m; vector<int> salarios(n); notas.resize(m); for (int i = 0; i < n; i++) { cin >> salarios[i]; } for (int i = 0; i < m; i++) { cin >> notas[i]; } for (int i = 0; i < n; i++) { memset(dp, -1, sizeof(dp)); if (!solve(salarios[i], 0, m)) { cout << "NO" << endl; return 0; } } cout << "YES" << endl; return 0; }

Compilation message (stderr)

bank.cpp: In function 'bool solve(int, int, int)':
bank.cpp:36:25: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   36 |     return dp[sum][idx] = pegar || n_pegar;
      |            ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...