Submission #170038

# Submission time Handle Problem Language Result Execution time Memory
170038 2019-12-23T19:05:00 Z tselmegkh Bank (IZhO14_bank) C++14
71 / 100
1000 ms 704 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 += b[i];
	}
	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 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 17 ms 376 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 17 ms 376 KB Output is correct
9 Correct 17 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 504 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 476 KB Output is correct
4 Correct 47 ms 604 KB Output is correct
5 Correct 7 ms 504 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 4 ms 376 KB Output is correct
8 Correct 4 ms 376 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 3 ms 508 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 17 ms 376 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 17 ms 376 KB Output is correct
9 Correct 17 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 380 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 4 ms 504 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 476 KB Output is correct
23 Correct 47 ms 604 KB Output is correct
24 Correct 7 ms 504 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 4 ms 376 KB Output is correct
27 Correct 4 ms 376 KB Output is correct
28 Correct 3 ms 504 KB Output is correct
29 Correct 3 ms 508 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Execution timed out 1063 ms 704 KB Time limit exceeded
32 Halted 0 ms 0 KB -