Submission #525077

#TimeUsernameProblemLanguageResultExecution timeMemory
525077Dilshod_ImomovBank (IZhO14_bank)C++17
100 / 100
158 ms10836 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; // const int INF = 1e18 + 7; int a[N], b[N], n, m; bool used[25][N], dp[25][N]; vector < int > vc[25]; string ans = "NO"; bool rec( int i, int mask ) { if ( i == 0 ) { return 1; } if ( used[i][mask] ) { return dp[i][mask]; } used[i][mask] = 1; for ( auto msk: vc[i] ) { if ( (msk & mask) == msk ) { int ok = rec( i - 1, mask ^ msk); if ( ok ) { dp[i][mask] = 1; break; } } } return dp[i][mask]; } int32_t main() { speed; cin >> n >> m; for ( int i = 1; i <= n; i++ ) { cin >> a[i]; } for ( int i = 0; i < m; i++ ) { cin >> b[i]; } for ( int msk = 0; msk < (1 << m); msk++ ) { int cnt = 0; for ( int j = 0; j < m; j++ ) { if ( (msk >> j) & 1 ) { cnt += b[j]; } } for ( int i = 1; i <= n; i++ ) { if ( cnt == a[i]) { vc[i].push_back(msk); } } } if ( rec( n, (1 << m) - 1 ) ) { cout << "YES\n"; } else { 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...