Submission #656387

#TimeUsernameProblemLanguageResultExecution timeMemory
656387iskhakkutbilimBank (IZhO14_bank)C++14
71 / 100
1095 ms8096 KiB
#include <bits/stdc++.h> using namespace std; //#define int long long #define ff first #define ss second #define all(a) a.begin(), a.end() const int M = 1e9 + 7; const int N = 21; int dp[N][1<<N], a[N], b[N]; int n, m; vector<int> g[N]; main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for(int i = 0;i < n; i++){ cin >> a[i]; } for(int i = 0;i < m; i++){ cin >> b[i]; } for(int mask = 0; mask < (1<<m); mask++){ int sum = 0; for(int i = 0;i < m; i++){ if(mask & (1<<i)){ sum+= b[i]; } } for(int i = 0;i < n; i++){ if(a[i] == sum){ g[i].push_back(mask); } } } for(int i = 0;i < n; i++){ if(g[i].empty()){ cout << "NO"; return 0; } } for(auto x : g[0]){ dp[0][x] = 1; } for(int i = 1;i < n; i++){ for(int mask = 0; mask < (1<<m); mask++){ // if(dp[i-1][mask] == 0){ // continue; // } for(auto x : g[i]){ if((mask & x) == 0 and dp[i-1][mask]==1){ dp[i][mask|x] = 1; } } } } for(int mask = 1; mask < (1<<m); mask++){ if(dp[n-1][mask] == 1){ cout << "YES"; return 0; } } cout << "NO"; return 0; }

Compilation message (stderr)

bank.cpp:14:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   14 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...