Submission #656411

#TimeUsernameProblemLanguageResultExecution timeMemory
656411asiatBank (IZhO14_bank)C++14
100 / 100
668 ms81028 KiB
#include <bits/stdc++.h> #define int long long #define endl '\n' using namespace std; const int N = 21; int dp[N][(1<<N)]; main(){ cin.tie(0)->sync_with_stdio(0); int n; cin >> n; int m; cin >> m; vector <int> v(n), g(m); vector <int> can[n+1]; for (int i = 0; i < n; i++)cin >> v[i]; for (int i = 0; i < m; i++)cin >> g[i]; for (int i = 1; i < (1<<m); i++){ int sum = 0; vector <int> ans; int x = i; while(x > 0){ ans.push_back(x&1); x>>=1; } while(ans.size() < m)ans.push_back(0); reverse(ans.begin(), ans.end()); cout << endl; for (int j = 0; j < m; j++) if(ans[j] == 1)sum+=g[j]; for (int j = 0; j < n; j++) if(sum == v[j])can[j].push_back(i); } if(n > m){ cout << "NO"; return 0; } for (auto to : can[0]){ dp[0][to] = 1; } for (int i = 1; i < n; i++) for (int mask = 1; mask < (1<<m); mask++){ if(!dp[i-1][mask])continue; for (auto to : can[i]) if(!(mask & to)) dp[i][mask|to] |= dp[i-1][mask]; } for (int i = 0; i < (1<<m); i++){ int to = dp[n-1][i]; if(to){ cout << "YES" << endl; return 0; } } cout << "NO" << endl; return 0; }

Compilation message (stderr)

bank.cpp:7:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    7 | main(){
      | ^~~~
bank.cpp: In function 'int main()':
bank.cpp:23:20: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   23 |   while(ans.size() < m)ans.push_back(0);
      |         ~~~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...