Submission #854291

#TimeUsernameProblemLanguageResultExecution timeMemory
854291WebbWayneBank (IZhO14_bank)C++14
71 / 100
1058 ms600 KiB
#include <iostream> #include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i, a, b) for(int i = a; i < b; i++) #define vi vector<int> #define ii pair<int, int> #define pb push_back #define f first #define s second #define all(i) (i).begin(), (i).end() #define MOD 1000000007 #define endl '\n' int n, m; vector<vi> common; void backtrack(int i, int state) { if(i == n) { cout<<"YES"<<endl; exit(0); } rep(j, 0, common[i].size()) { int mask = common[i][j]; if(mask & state) continue; backtrack(i+1, state | mask); } // return; } int main() { cin.tie(NULL); ios_base::sync_with_stdio(NULL); cin>>n>>m; vi nums(n); vi bank(m); common.resize(n); rep(i, 0, n) cin>>nums[i]; rep(i, 0, m) cin>>bank[i]; for(int mask = 0; mask < (1<<m); mask++) { int sum = 0; for(int i = 0; i < m; i++) if(mask & (1<<i)) sum += bank[i]; for(int i = 0; i < n; i++) if(sum == nums[i]) common[i].pb(mask); //this is a possible combination that could make my sum happen. } backtrack(0, 0); cout<<"NO"<<endl; return 0; }

Compilation message (stderr)

bank.cpp: In function 'void backtrack(int, int)':
bank.cpp:7:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 | #define rep(i, a, b) for(int i = a; i < b; i++)
......
   26 |     rep(j, 0, common[i].size()) {
      |         ~~~~~~~~~~~~~~~~~~~~~~         
bank.cpp:26:5: note: in expansion of macro 'rep'
   26 |     rep(j, 0, common[i].size()) {
      |     ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...