# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
892434 | I_FloPPed21 | Bank (IZhO14_bank) | C++14 | 941 ms | 262144 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int n, m ;
int v[ 21 ], b [ 21 ] ;
bool dp [21 ] [ 1200000 ];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m ;
for ( int i = 1; i <= n ; i ++ )
{
cin >> v[ i ] ;
}
for ( int i = 1; i <= m ; i ++ )
cin >> b[ i ] ;
vector<int> posib [ n + 2] ;
vector<int> posixor[ n + 2] ;
posixor [ 1 ] .push_back(0);
dp [ 0 ][ 0 ] = true ;
for ( int i = 1 ; i <= n ; i ++ )
{
for ( int j = 0 ; j < ( 1 << m ) ; j ++ )
{
int sum = 0 ;
for ( int f = 1 ; f <= m ; f ++ )
{
if ( j & ( 1 << ( f - 1 ) ) )
sum += b[ f ] ;
}
if ( sum == v[ i ] )
{
posib [ i ] .push_back( j ) ;
}
}
if ( posib[ i ] .size() == 0 )
{
cout << "NO" << '\n';
return 0 ;
}
for ( int d = 0 ; d < posixor [ i ] .size() ; d ++ )
{
long long j = posixor [ i ][ d ] ;
if ( dp [ i - 1 ] [ j ] == true )
{
for (int k = 0 ; k < posib [ i ] .size() ; k ++ )
{
if ( (( j ) & ( posib [ i ][ k ] )) == 0 )
{
int val = (posib [ i ][ k ] | ( j ));
posixor [ i + 1] .push_back(val);
dp [ i ] [ val ] = true ;
if ( i == n )
{
cout << "YES" << '\n';
return 0 ;
}
}
}
}
}
}
cout << "NO" << '\n';
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |