Submission #727429

#TimeUsernameProblemLanguageResultExecution timeMemory
727429josiftepeBank (IZhO14_bank)C++14
0 / 100
41 ms82580 KiB
#include <iostream> #include <fstream> #include <vector> #include <map> #include <cstring> #include <queue> #include <algorithm> //#include <bits/stdc++.h> using namespace std; const int maxn = 1005; vector<int> masks[maxn]; int salary[maxn]; int notes[maxn]; int dp[20][1 << 20]; int rec(int at, int bitmask) { if(at == -1) { return 1; } if(dp[at][bitmask] != -1) { return dp[at][bitmask]; } int result = 1; for(int i = 0; i < masks[salary[at]].size(); i++) { int tmp_mask = masks[salary[at]][i]; if((tmp_mask & bitmask) == tmp_mask) { if(rec(at - 1, bitmask ^ tmp_mask)) { return dp[at][bitmask] = 1; } } } return dp[at][bitmask] = 0; } int main() { ios::sync_with_stdio(0); int n, m; cin >> n >> m; for(int i = 0; i < n; i++) { cin >> salary[i]; } for(int i = 0; i < m; i++) { cin >> notes[i]; } for(int bitmask = 0; bitmask < (1 << m); bitmask++) { int sum = 0; for(int i = 0; i < m; i++) { if(bitmask & (1 << i)) { sum += notes[i]; } } masks[sum].push_back(bitmask); } memset(dp, -1, sizeof dp); cout << (rec(n - 1, (1 << m) - 1) == 1 ? "YES" : "NO") << endl; return 0; }

Compilation message (stderr)

bank.cpp: In function 'int rec(int, int)':
bank.cpp:25:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for(int i = 0; i < masks[salary[at]].size(); i++) {
      |                    ~~^~~~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:24:9: warning: unused variable 'result' [-Wunused-variable]
   24 |     int result = 1;
      |         ^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...