#include <iostream>
#define MAXN 21
#define intt long long
using namespace std ;
intt a[MAXN] , b[MAXN] , n , m , f ;
intt d ( intt p ) {
if ( p == m ) f = 1 ;
if ( f ) return 0 ;
for ( int i = 0 ; i <= ( 1 << ( n - 1 ) ) ; i ++ ) {
if ( f ) return 0 ;
intt x = 0 ;
for ( int j = 0 ; j < n ; j ++ ) {
if ( ( 1 << j ) & i ) {
x += a[j] ;
if ( a[j] == -1 ) {
x = -1 ;
break ;
}
}
}
if ( x == -1 ) continue ;
if ( x == b[p] ) {
intt z[MAXN] ;
for ( int j = 0 ; j < n ; j ++ ) {
if ( ( 1 << j ) & i ) z[j] = a[j] , a[j] = -1 ;
}
d ( p + 1 ) ;
if ( f ) return 0 ;
for ( int j = 0 ; j < n ; j ++ ) {
if ( ( 1 << j ) & i ) a[j] = z[j] ;
}
}
}
return 0 ;
}
int main () {
cin >> m >> n ;
for ( int i = 0 ; i < m ; i ++ ) cin >> b[i] ;
for ( int i = 0 ; i < n ; i ++ ) cin >> a[i] ;
d ( 0 ) ;
if ( f ) cout << "YES\n" ;
else cout << "NO\n" ;
return 0 ;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
500 KB |
Output is correct |
3 |
Correct |
2 ms |
500 KB |
Output is correct |
4 |
Correct |
2 ms |
500 KB |
Output is correct |
5 |
Correct |
34 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
576 KB |
Output is correct |
8 |
Correct |
2 ms |
588 KB |
Output is correct |
9 |
Correct |
34 ms |
588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
500 KB |
Output is correct |
3 |
Correct |
2 ms |
500 KB |
Output is correct |
4 |
Correct |
2 ms |
500 KB |
Output is correct |
5 |
Correct |
34 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
576 KB |
Output is correct |
8 |
Correct |
2 ms |
588 KB |
Output is correct |
9 |
Correct |
34 ms |
588 KB |
Output is correct |
10 |
Incorrect |
3 ms |
588 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |