제출 #338414

#제출 시각아이디문제언어결과실행 시간메모리
338414Dilshod_Imomov은행 (IZhO14_bank)C++17
100 / 100
415 ms10860 KiB
# include <bits/stdc++.h> # define speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) # define int long long # define fi first # define se second using namespace std; const int N = 2e6 + 7; const int mod = 1e9 + 7; int n, m, a[23], b[23]; vector < int > vc[1007]; bool used[23][N]; void rec( int i, int mask ) { if ( i < 0 ) { cout << "YES"; exit(0); } if ( used[i][mask] ) { return; } used[i][mask] = 1; for ( auto msk: vc[ a[i] ] ) { if ( (mask & msk) == msk ) { rec( i - 1, (mask ^ msk) ); } } } int32_t main() { speed; 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 bit = 0; bit < m; bit++ ) { if ( (mask >> bit) & 1 ) { sum += b[bit]; } } for ( int i = 0; i < n; i++ ) { if ( sum == a[i] ) { vc[ a[i] ].push_back(mask); // cout << a[i] << ' ' << mask << endl; } } } rec( n - 1, (1 << (m)) - 1 ); cout << "NO"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...