Submission #763351

#TimeUsernameProblemLanguageResultExecution timeMemory
763351BlagojBank (IZhO14_bank)C++17
19 / 100
59 ms3176 KiB
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,unroll-loops") using namespace std; #define endl '\n' #define ll long long #define all(x) x.begin(), x.end() int n, m; vector<int> s, v; int dp[20][1 << 20]; int solve(int p, int mask) { if (p == n) return dp[p][mask] = 1; if (mask == (1 << v.size()) - 1) return dp[p][mask] = -1; if (dp[p][mask] != 0) return dp[p][mask]; vector<int> c; for (int i = 0; i < m; i++) if (!(mask & (1 << i))) c.push_back(i); dp[p][mask] = -1; for (int i = 0; i < (1 << c.size()); i++) { int sum = 0; for (int j = 0; j < c.size(); j++) if (i & (1 << j)) sum += v[c[j]]; if (sum == s[p]) dp[p][mask] = max(dp[p][mask], solve(p + 1, mask | i)); } return dp[p][mask]; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; s.resize(n); v.resize(m); for (int i = 0; i < n; i++) cin >> s[i]; for (int i = 0; i < m; i++) cin >> v[i]; sort(all(s)); sort(all(v)); solve(0, 0); cout << (dp[0][0] == 1 ? "YES" : "NO"); }

Compilation message (stderr)

bank.cpp: In function 'int solve(int, int)':
bank.cpp:24:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |         for (int j = 0; j < c.size(); j++) if (i & (1 << j)) sum += v[c[j]];
      |                         ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...