Submission #83377

# Submission time Handle Problem Language Result Execution time Memory
83377 2018-11-07T12:54:44 Z Nordway Bank (IZhO14_bank) C++14
100 / 100
309 ms 55112 KB
#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define boost ios_base::sync_with_stdio(0),cin.tie(0),cout.tie()

using namespace std;

typedef unsigned long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;

const ll INF = 1e18;
const int inf = INT_MAX;
const ll mod = 1e9 + 7;
const int pi = acos(-1);
const int dx[4] = {0, 1, 0, 0};
const int dy[4] = {1, 0, 0, 0};
const int N = 21;
const int MAXN = 1e6 + 1;

int n, m;
int a[N], b[N], sum[(1 << N)], used[N][(1 << N)];
vector < int > g[N];

void calc(int v, int mask){
	if(v == n + 1){
		cout << "YES";
		exit(0);
	}
	if(used[v][mask])return;
	used[v][mask] = 1;
	for(int i = 0; i < sz(g[v]); i++){
		if(!(mask & g[v][i]))calc(v + 1, mask | g[v][i]);
	}
}

int main(){
	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 mask = 1; mask < (1 << m); mask++){
		for(int i = 0; i < m; i++){
			if((mask >> i) & 1)sum[mask] += b[i];
		}
	}
	for(int i = 1; i <= n; i++){
		for(int mask = 1; mask < (1 << m); mask++){
			if(a[i] == sum[mask])g[i].pb(mask);
		}
	}
	calc(1, 0);
	cout << "NO";
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 508 KB Output is correct
3 Correct 2 ms 508 KB Output is correct
4 Correct 3 ms 616 KB Output is correct
5 Correct 69 ms 4584 KB Output is correct
6 Correct 2 ms 4584 KB Output is correct
7 Correct 2 ms 4584 KB Output is correct
8 Correct 69 ms 4640 KB Output is correct
9 Correct 70 ms 4768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4768 KB Output is correct
2 Correct 2 ms 4768 KB Output is correct
3 Correct 2 ms 4768 KB Output is correct
4 Correct 2 ms 4768 KB Output is correct
5 Correct 2 ms 4768 KB Output is correct
6 Correct 2 ms 4768 KB Output is correct
7 Correct 2 ms 4768 KB Output is correct
8 Correct 2 ms 4768 KB Output is correct
9 Correct 2 ms 4768 KB Output is correct
10 Correct 2 ms 4768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4768 KB Output is correct
2 Correct 2 ms 4768 KB Output is correct
3 Correct 3 ms 4768 KB Output is correct
4 Correct 3 ms 4768 KB Output is correct
5 Correct 3 ms 4768 KB Output is correct
6 Correct 3 ms 4768 KB Output is correct
7 Correct 3 ms 4768 KB Output is correct
8 Correct 5 ms 4768 KB Output is correct
9 Correct 3 ms 4768 KB Output is correct
10 Correct 3 ms 4768 KB Output is correct
11 Correct 3 ms 4768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 508 KB Output is correct
3 Correct 2 ms 508 KB Output is correct
4 Correct 3 ms 616 KB Output is correct
5 Correct 69 ms 4584 KB Output is correct
6 Correct 2 ms 4584 KB Output is correct
7 Correct 2 ms 4584 KB Output is correct
8 Correct 69 ms 4640 KB Output is correct
9 Correct 70 ms 4768 KB Output is correct
10 Correct 2 ms 4768 KB Output is correct
11 Correct 2 ms 4768 KB Output is correct
12 Correct 2 ms 4768 KB Output is correct
13 Correct 2 ms 4768 KB Output is correct
14 Correct 2 ms 4768 KB Output is correct
15 Correct 2 ms 4768 KB Output is correct
16 Correct 2 ms 4768 KB Output is correct
17 Correct 2 ms 4768 KB Output is correct
18 Correct 2 ms 4768 KB Output is correct
19 Correct 2 ms 4768 KB Output is correct
20 Correct 3 ms 4768 KB Output is correct
21 Correct 2 ms 4768 KB Output is correct
22 Correct 3 ms 4768 KB Output is correct
23 Correct 3 ms 4768 KB Output is correct
24 Correct 3 ms 4768 KB Output is correct
25 Correct 3 ms 4768 KB Output is correct
26 Correct 3 ms 4768 KB Output is correct
27 Correct 5 ms 4768 KB Output is correct
28 Correct 3 ms 4768 KB Output is correct
29 Correct 3 ms 4768 KB Output is correct
30 Correct 3 ms 4768 KB Output is correct
31 Correct 71 ms 4768 KB Output is correct
32 Correct 74 ms 4768 KB Output is correct
33 Correct 82 ms 4768 KB Output is correct
34 Correct 90 ms 4768 KB Output is correct
35 Correct 93 ms 4860 KB Output is correct
36 Correct 114 ms 4864 KB Output is correct
37 Correct 70 ms 4864 KB Output is correct
38 Correct 74 ms 4864 KB Output is correct
39 Correct 85 ms 4864 KB Output is correct
40 Correct 91 ms 4864 KB Output is correct
41 Correct 113 ms 4864 KB Output is correct
42 Correct 94 ms 14204 KB Output is correct
43 Correct 86 ms 14204 KB Output is correct
44 Correct 102 ms 14204 KB Output is correct
45 Correct 73 ms 14204 KB Output is correct
46 Correct 81 ms 14204 KB Output is correct
47 Correct 102 ms 14204 KB Output is correct
48 Correct 70 ms 14204 KB Output is correct
49 Correct 70 ms 14204 KB Output is correct
50 Correct 113 ms 14204 KB Output is correct
51 Correct 91 ms 14204 KB Output is correct
52 Correct 91 ms 14204 KB Output is correct
53 Correct 91 ms 14204 KB Output is correct
54 Correct 113 ms 14204 KB Output is correct
55 Correct 113 ms 14204 KB Output is correct
56 Correct 111 ms 14204 KB Output is correct
57 Correct 309 ms 55112 KB Output is correct
58 Correct 112 ms 55112 KB Output is correct