Submission #318392

# Submission time Handle Problem Language Result Execution time Memory
318392 2020-11-01T18:05:44 Z Gurban Bank (IZhO14_bank) C++17
100 / 100
483 ms 26396 KB
#include <bits/stdc++.h>
using namespace std;
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")

using ll = long long;

const int maxn=22;
const int N = 1<<maxn;
int n,m,a[maxn],b[maxn],sum[N],p[maxn],x;
bool can[maxn][N],dp[maxn][N];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> n >> m;
	for(int i = 1;i <= n;i++) cin >> a[i],p[i]=p[i-1]+a[i];
	for(int i = 0;i < m;i++) cin >> b[i];

	for(int i = 0;i < (1<<m);i++){
		can[0][i]=1;
		for(int j = 0;j < m;j++) if(i & (1<<j)) sum[i] += b[j];
	}

	for(int i = 1;i <= n;i++){
		for(int j = 0;j < (1 << m);j++){
			if(sum[j]==p[i]) can[i][j]=can[i-1][j];
			x = j;
			while(x >= 1){
				int now = x&-x;
				can[i][j] |= can[i][j-now];
				x -= now;
			}
			// for(int k = 0;k < m;k++) if((1<<k) & j) if(can[i][j-(1<<k)] == 1) can[i][j]=1;
		}
	}
	
	// for(int i = 1;i <= n;i++){
	// 	cout<<i<<" ---> ";
	// 	for(int j = 0;j < (1<<m);j++) if(can[i][j] == 1) cout<<j<<' ';
	// 	cout<<'\n';
	// }

	if(can[n][(1<<m) - 1]) cout<<"YES";
	else cout<<"NO";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 3 ms 492 KB Output is correct
5 Correct 86 ms 6496 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 86 ms 6504 KB Output is correct
9 Correct 86 ms 6500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 620 KB Output is correct
2 Correct 2 ms 492 KB Output is correct
3 Correct 4 ms 620 KB Output is correct
4 Correct 4 ms 748 KB Output is correct
5 Correct 3 ms 620 KB Output is correct
6 Correct 3 ms 492 KB Output is correct
7 Correct 2 ms 492 KB Output is correct
8 Correct 3 ms 620 KB Output is correct
9 Correct 3 ms 620 KB Output is correct
10 Correct 3 ms 620 KB Output is correct
11 Correct 4 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 3 ms 492 KB Output is correct
5 Correct 86 ms 6496 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 86 ms 6504 KB Output is correct
9 Correct 86 ms 6500 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 3 ms 620 KB Output is correct
21 Correct 2 ms 492 KB Output is correct
22 Correct 4 ms 620 KB Output is correct
23 Correct 4 ms 748 KB Output is correct
24 Correct 3 ms 620 KB Output is correct
25 Correct 3 ms 492 KB Output is correct
26 Correct 2 ms 492 KB Output is correct
27 Correct 3 ms 620 KB Output is correct
28 Correct 3 ms 620 KB Output is correct
29 Correct 3 ms 620 KB Output is correct
30 Correct 4 ms 748 KB Output is correct
31 Correct 106 ms 7580 KB Output is correct
32 Correct 126 ms 8548 KB Output is correct
33 Correct 208 ms 12864 KB Output is correct
34 Correct 263 ms 15844 KB Output is correct
35 Correct 283 ms 16868 KB Output is correct
36 Correct 466 ms 26352 KB Output is correct
37 Correct 106 ms 7524 KB Output is correct
38 Correct 146 ms 9832 KB Output is correct
39 Correct 224 ms 13796 KB Output is correct
40 Correct 268 ms 15844 KB Output is correct
41 Correct 462 ms 26396 KB Output is correct
42 Correct 165 ms 10724 KB Output is correct
43 Correct 227 ms 13796 KB Output is correct
44 Correct 361 ms 20964 KB Output is correct
45 Correct 128 ms 8596 KB Output is correct
46 Correct 188 ms 11904 KB Output is correct
47 Correct 365 ms 21092 KB Output is correct
48 Correct 89 ms 6504 KB Output is correct
49 Correct 89 ms 6500 KB Output is correct
50 Correct 465 ms 26212 KB Output is correct
51 Correct 270 ms 15996 KB Output is correct
52 Correct 268 ms 15844 KB Output is correct
53 Correct 267 ms 15844 KB Output is correct
54 Correct 465 ms 26212 KB Output is correct
55 Correct 464 ms 26212 KB Output is correct
56 Correct 464 ms 26212 KB Output is correct
57 Correct 483 ms 26300 KB Output is correct
58 Correct 443 ms 25156 KB Output is correct