Submission #1107495

#TimeUsernameProblemLanguageResultExecution timeMemory
1107495vjudge1Bank (IZhO14_bank)C++17
71 / 100
1075 ms10160 KiB
#include <bits/stdc++.h> using namespace std; #define nl '\n' #define pb push_back const int N = 1e5 + 1; int n, m, a[21], b[21]; vector< int >mp[N]; bool ch; void rec( int i, vector< int >v ) { if( i == n ) { cout <<"YES\n"; exit(0); } for( int x: mp[a[i]] ) { bool ch1 = true; for( int j: v ) if( (x & j) ) { ch1 = false; break; } if( ch1 ) { v.pb( x ); rec(i + 1, v); v.pop_back(); } } } void solve() { cin >>n >>m; for( int i = 0; i < n; ++i ) cin >>a[i]; for( int j = 0; j < m; ++j ) cin >>b[j]; for( int mask = 0; mask < (1 << m); ++mask ) { int sum = 0; for( int i = 0; i < m; ++i ) if( (1 << i) & mask ) sum += b[i]; mp[sum].pb( mask ); } rec(0, {}); cout <<"NO\n"; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int T = 1; // cin >>T; while( T-- ) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...