Submission #90784

# Submission time Handle Problem Language Result Execution time Memory
90784 2018-12-24T11:57:15 Z daniel_02 Bank (IZhO14_bank) C++17
100 / 100
374 ms 33320 KB
#include <bits/stdc++.h>

#define fr first
#define pb push_back
#define sc second
#define ll long long

using namespace std;

const int N = 23;

int a[N], b[N];
bool dp[N][(1 << 20) + 7];
vector<int>vec[(1 << 20) + 7];
bool us[(1 << 20) + 7];
vector<int>masks;

main()
{
	int n, m, x;
	
	cin >> n >> m;

	for (int i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
	}
	for (int i = 0; i < m; i++)
	{
		scanf("%d", &b[i]);
	}
	for (int mask = 1; mask < (1 << m); mask++)
	{
		int sm = 0;
		for (int i = 0; i < m; i++)
		{	
			if (mask & (1 << i))
				sm += b[i];
		}
		vec[sm].pb(mask);
	}
	int sum = 0;
	for (int i = 0; i < n; i++)
	{
		sum += a[i];
		masks.clear();
		for (int j = 0; j < vec[sum].size(); j++)
		{
			int mask = vec[sum][j];
			if (i == 0 || us[mask])masks.pb(mask);
		}
		if (masks.size() == 0)
		{
			puts("NO");
			return 0;
		}
		memset(us, 0, sizeof(us));
		for (int j = 0; j < masks.size(); j++)
		{
			int mask = masks[j];
			us[mask] = 1;
		}
		for (int mask = 1; mask < (1 << m); mask++)
		{
			if (us[mask])
			{
				for (int j = 0; j < m; j++)
				{
					us[mask | (1 << j)] = 1;
				}
			}
		}
	}
	puts("YES");
}
/*
4 20
5 5 5 5
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
*/

Compilation message

bank.cpp:18:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
bank.cpp: In function 'int main()':
bank.cpp:47:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j = 0; j < vec[sum].size(); j++)
                   ~~^~~~~~~~~~~~~~~~~
bank.cpp:58:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j = 0; j < masks.size(); j++)
                   ~~^~~~~~~~~~~~~~
bank.cpp:20:12: warning: unused variable 'x' [-Wunused-variable]
  int n, m, x;
            ^
bank.cpp:26:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i]);
   ~~~~~^~~~~~~~~~~~~
bank.cpp:30:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &b[i]);
   ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 21 ms 25980 KB Output is correct
2 Correct 20 ms 25980 KB Output is correct
3 Correct 20 ms 26048 KB Output is correct
4 Correct 23 ms 26320 KB Output is correct
5 Correct 95 ms 31628 KB Output is correct
6 Correct 24 ms 31628 KB Output is correct
7 Correct 23 ms 31628 KB Output is correct
8 Correct 107 ms 31700 KB Output is correct
9 Correct 93 ms 31700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 31700 KB Output is correct
2 Correct 24 ms 31700 KB Output is correct
3 Correct 25 ms 31700 KB Output is correct
4 Correct 24 ms 31700 KB Output is correct
5 Correct 25 ms 31700 KB Output is correct
6 Correct 25 ms 31700 KB Output is correct
7 Correct 24 ms 31700 KB Output is correct
8 Correct 25 ms 31700 KB Output is correct
9 Correct 24 ms 31700 KB Output is correct
10 Correct 25 ms 31700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 31700 KB Output is correct
2 Correct 25 ms 31700 KB Output is correct
3 Correct 26 ms 31700 KB Output is correct
4 Correct 25 ms 31700 KB Output is correct
5 Correct 22 ms 31700 KB Output is correct
6 Correct 23 ms 31700 KB Output is correct
7 Correct 23 ms 31700 KB Output is correct
8 Correct 23 ms 31700 KB Output is correct
9 Correct 23 ms 31700 KB Output is correct
10 Correct 27 ms 31700 KB Output is correct
11 Correct 24 ms 31700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 25980 KB Output is correct
2 Correct 20 ms 25980 KB Output is correct
3 Correct 20 ms 26048 KB Output is correct
4 Correct 23 ms 26320 KB Output is correct
5 Correct 95 ms 31628 KB Output is correct
6 Correct 24 ms 31628 KB Output is correct
7 Correct 23 ms 31628 KB Output is correct
8 Correct 107 ms 31700 KB Output is correct
9 Correct 93 ms 31700 KB Output is correct
10 Correct 24 ms 31700 KB Output is correct
11 Correct 24 ms 31700 KB Output is correct
12 Correct 25 ms 31700 KB Output is correct
13 Correct 24 ms 31700 KB Output is correct
14 Correct 25 ms 31700 KB Output is correct
15 Correct 25 ms 31700 KB Output is correct
16 Correct 24 ms 31700 KB Output is correct
17 Correct 25 ms 31700 KB Output is correct
18 Correct 24 ms 31700 KB Output is correct
19 Correct 25 ms 31700 KB Output is correct
20 Correct 26 ms 31700 KB Output is correct
21 Correct 25 ms 31700 KB Output is correct
22 Correct 26 ms 31700 KB Output is correct
23 Correct 25 ms 31700 KB Output is correct
24 Correct 22 ms 31700 KB Output is correct
25 Correct 23 ms 31700 KB Output is correct
26 Correct 23 ms 31700 KB Output is correct
27 Correct 23 ms 31700 KB Output is correct
28 Correct 23 ms 31700 KB Output is correct
29 Correct 27 ms 31700 KB Output is correct
30 Correct 24 ms 31700 KB Output is correct
31 Correct 106 ms 32660 KB Output is correct
32 Correct 119 ms 32660 KB Output is correct
33 Correct 124 ms 32660 KB Output is correct
34 Correct 134 ms 32660 KB Output is correct
35 Correct 131 ms 33180 KB Output is correct
36 Correct 143 ms 33180 KB Output is correct
37 Correct 105 ms 33320 KB Output is correct
38 Correct 96 ms 33320 KB Output is correct
39 Correct 345 ms 33320 KB Output is correct
40 Correct 101 ms 33320 KB Output is correct
41 Correct 98 ms 33320 KB Output is correct
42 Correct 136 ms 33320 KB Output is correct
43 Correct 258 ms 33320 KB Output is correct
44 Correct 160 ms 33320 KB Output is correct
45 Correct 146 ms 33320 KB Output is correct
46 Correct 134 ms 33320 KB Output is correct
47 Correct 126 ms 33320 KB Output is correct
48 Correct 112 ms 33320 KB Output is correct
49 Correct 94 ms 33320 KB Output is correct
50 Correct 355 ms 33320 KB Output is correct
51 Correct 158 ms 33320 KB Output is correct
52 Correct 198 ms 33320 KB Output is correct
53 Correct 196 ms 33320 KB Output is correct
54 Correct 372 ms 33320 KB Output is correct
55 Correct 350 ms 33320 KB Output is correct
56 Correct 374 ms 33320 KB Output is correct
57 Correct 344 ms 33320 KB Output is correct
58 Correct 349 ms 33320 KB Output is correct