Submission #392464

# Submission time Handle Problem Language Result Execution time Memory
392464 2021-04-21T08:05:46 Z patrikpavic2 Bank (IZhO14_bank) C++17
100 / 100
115 ms 14764 KB
#include <cstdio>
#include <vector>
#include <cstring>

#define PB push_back

using namespace std;

const int N = 20;
const int MSK = (1 << 20);

vector < int > v[N];
int A[N], B[N], n, m, P[N];
int dp[MSK], sm[MSK];

int main(){
	scanf("%d%d", &n, &m);
	for(int i = 0;i < n;i++){
		scanf("%d", A + i);
		P[i] = A[i] + (i ? P[i - 1] : 0);
	}
	for(int i = 0;i < m;i++)
		scanf("%d", B + i);
	for(int msk = 0;msk < (1 << m);msk++){
		for(int i = 0;i < m;i++)
			sm[msk] += B[i] * !!(msk & (1 << i));
		int gd = 0;
		while(gd < n && P[gd] < sm[msk]) gd++;
		v[gd].PB(msk); dp[msk] = 1;
	}
	for(int i = 1;i <= n;i++){
		vector < int > dobri;
		for(int x : v[i - 1]) 
			if(sm[x] == P[i - 1] && dp[x])
				dobri.PB(x);
		memset(dp, 0, sizeof(dp));
		if(i == n){
			printf((int)dobri.size() ? "YES\n" : "NO\n");
			return 0;
		}
		memset(dp, 0, sizeof(dp));
		for(int x : dobri) dp[x] = 1;
		for(int j = 0;j < m;j++){
			for(int x : v[i]){
				if(x & (1 << j))
					dp[x] |= dp[x ^ (1 << j)];
			}
		}
	}
	return 0;
}

Compilation message

bank.cpp: In function 'int main()':
bank.cpp:17:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   17 |  scanf("%d%d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~
bank.cpp:19:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   19 |   scanf("%d", A + i);
      |   ~~~~~^~~~~~~~~~~~~
bank.cpp:23:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   23 |   scanf("%d", B + i);
      |   ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4300 KB Output is correct
2 Correct 2 ms 4396 KB Output is correct
3 Correct 2 ms 4300 KB Output is correct
4 Correct 3 ms 4708 KB Output is correct
5 Correct 34 ms 12744 KB Output is correct
6 Correct 2 ms 4300 KB Output is correct
7 Correct 2 ms 4300 KB Output is correct
8 Correct 36 ms 14036 KB Output is correct
9 Correct 34 ms 12608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4300 KB Output is correct
2 Correct 3 ms 4300 KB Output is correct
3 Correct 3 ms 4300 KB Output is correct
4 Correct 4 ms 4300 KB Output is correct
5 Correct 5 ms 4388 KB Output is correct
6 Correct 4 ms 4300 KB Output is correct
7 Correct 4 ms 4300 KB Output is correct
8 Correct 4 ms 4300 KB Output is correct
9 Correct 3 ms 4300 KB Output is correct
10 Correct 4 ms 4304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4684 KB Output is correct
2 Correct 4 ms 4556 KB Output is correct
3 Correct 8 ms 4564 KB Output is correct
4 Correct 8 ms 4572 KB Output is correct
5 Correct 7 ms 4512 KB Output is correct
6 Correct 4 ms 4556 KB Output is correct
7 Correct 5 ms 4556 KB Output is correct
8 Correct 4 ms 4516 KB Output is correct
9 Correct 6 ms 4556 KB Output is correct
10 Correct 8 ms 4556 KB Output is correct
11 Correct 8 ms 4516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4300 KB Output is correct
2 Correct 2 ms 4396 KB Output is correct
3 Correct 2 ms 4300 KB Output is correct
4 Correct 3 ms 4708 KB Output is correct
5 Correct 34 ms 12744 KB Output is correct
6 Correct 2 ms 4300 KB Output is correct
7 Correct 2 ms 4300 KB Output is correct
8 Correct 36 ms 14036 KB Output is correct
9 Correct 34 ms 12608 KB Output is correct
10 Correct 4 ms 4300 KB Output is correct
11 Correct 3 ms 4300 KB Output is correct
12 Correct 3 ms 4300 KB Output is correct
13 Correct 4 ms 4300 KB Output is correct
14 Correct 5 ms 4388 KB Output is correct
15 Correct 4 ms 4300 KB Output is correct
16 Correct 4 ms 4300 KB Output is correct
17 Correct 4 ms 4300 KB Output is correct
18 Correct 3 ms 4300 KB Output is correct
19 Correct 4 ms 4304 KB Output is correct
20 Correct 7 ms 4684 KB Output is correct
21 Correct 4 ms 4556 KB Output is correct
22 Correct 8 ms 4564 KB Output is correct
23 Correct 8 ms 4572 KB Output is correct
24 Correct 7 ms 4512 KB Output is correct
25 Correct 4 ms 4556 KB Output is correct
26 Correct 5 ms 4556 KB Output is correct
27 Correct 4 ms 4516 KB Output is correct
28 Correct 6 ms 4556 KB Output is correct
29 Correct 8 ms 4556 KB Output is correct
30 Correct 8 ms 4516 KB Output is correct
31 Correct 63 ms 13756 KB Output is correct
32 Correct 69 ms 14764 KB Output is correct
33 Correct 92 ms 13344 KB Output is correct
34 Correct 97 ms 13364 KB Output is correct
35 Correct 100 ms 13412 KB Output is correct
36 Correct 110 ms 13928 KB Output is correct
37 Correct 35 ms 12588 KB Output is correct
38 Correct 37 ms 12760 KB Output is correct
39 Correct 61 ms 13844 KB Output is correct
40 Correct 76 ms 13204 KB Output is correct
41 Correct 112 ms 12892 KB Output is correct
42 Correct 90 ms 12940 KB Output is correct
43 Correct 100 ms 13884 KB Output is correct
44 Correct 103 ms 12844 KB Output is correct
45 Correct 72 ms 13668 KB Output is correct
46 Correct 93 ms 12996 KB Output is correct
47 Correct 103 ms 13508 KB Output is correct
48 Correct 36 ms 13420 KB Output is correct
49 Correct 35 ms 12660 KB Output is correct
50 Correct 113 ms 14620 KB Output is correct
51 Correct 87 ms 14580 KB Output is correct
52 Correct 97 ms 13856 KB Output is correct
53 Correct 97 ms 13812 KB Output is correct
54 Correct 114 ms 14584 KB Output is correct
55 Correct 112 ms 14536 KB Output is correct
56 Correct 111 ms 14472 KB Output is correct
57 Correct 111 ms 14508 KB Output is correct
58 Correct 115 ms 14648 KB Output is correct