# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
170037 |
2019-12-23T19:04:25 Z |
tselmegkh |
Bank (IZhO14_bank) |
C++14 |
|
2 ms |
376 KB |
#include<bits/stdc++.h>
using namespace std;
int a[25], b[25], n, m;
bool dp[25][(1 << 21)];
bool vis[25][(1 << 21)];
inline bool go(int v, int mask){
if(v == n){
return 1;
}
if(vis[v][mask])return dp[v][mask];
vis[v][mask] = 1;
bool possible = 0;
int totsum = 0;
for(int i = 0; i < m; i++){
if(!(mask & (1 << i)))totsum += mask;
}
if(totsum < a[v]){
return 0;
}
for(int i = 0; i < (1 << m); i++){
int sum = 0;
int tmp = i;
while(tmp){
int lsone = (tmp) & (-tmp);
int j = __builtin_ctz(lsone);
sum += b[j];
tmp -= lsone;
}
if(sum == a[v] && !(i & mask)){
possible |= go(v + 1, mask | i);
}
}
return dp[v][mask] = possible;
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> m;
for(int i = 0; i < n; i++){
cin >> a[i];
}
sort(a, a + n, greater<int>());
for(int i = 0; i < m; i++){
cin >> b[i];
}
if(go(0, 0)){
cout << "YES\n";
}else{
cout << "NO\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |