Submission #68487

# Submission time Handle Problem Language Result Execution time Memory
68487 2018-08-17T08:12:07 Z MrTEK Bank (IZhO14_bank) C++14
100 / 100
431 ms 22888 KB
#include <bits/stdc++.h>
 
using namespace std;
#define mp make_pair
#define pb push_back
#define len(a) (int)a.size()
#define fi first
#define sc second
#define cout maltahsin
#define left ind + ind
#define right ind + ind + 1
#define mid (l + r) / 2 
#define d1(w) cerr<<#w<<":"<<w<<endl;
#define d2(w,c) cerr<<#w<<":"<<w<<" "<<#c<<":"<<c<<endl;
#define d3(w,c,z) cerr<<#w<<":"<<w<<" "<<#c<<":"<<c<<" "<<#z<<":"<<z<<endl;
#define FAST_IO ios_base::sync_with_stdio(false);
#define endl '\n'
 
const int maxn = 620;
const long long LINF = 1e18;
const int LOG = 31;
const int INF = 1e9 + 5;
const int N = 20;
const int M = (2 << 20) + 5;
const int K = 1e3 + 5;
const int SQ = 350;
const int MOD = 998244353;
 
typedef pair <int,int> pii;

vector <int> S[K];

int n,m,dp[2][M],a[N],b[N];

void brute(int cur,int sum,int mask) {
	if (cur == m) {
		if (sum <= 1e3) S[sum].push_back(mask);
		return;
	}
	brute(cur + 1,sum,mask);
	brute(cur + 1,sum + b[cur],mask + (1 << cur));
}

int main() {

	scanf("%d %d",&n,&m);

	for (int i = 0 ; i < n ; i++) scanf("%d",&a[i]);
	for (int i = 0 ; i < m ; i++) scanf("%d",&b[i]);

	brute(0,0,0);

	dp[0][0] = 1;

	int cur = 0, nxt = 1;
	
	for (int i = 0 ; i < n ; i++) {
		for (int j = 0 ; j < M ; j++) {
			if (!dp[cur][j]) continue;
			for (auto it : S[a[i]]) {
				if ((j & it) == 0) {
					dp[nxt][j + it] |= dp[cur][j];
				}
			}
		}
		for (int j = 0 ; j < M ; j++) dp[cur][j] = 0;
		swap(cur,nxt);
	}
	int ans = 0;
	for (int i = 0 ; i < M ; i++) ans |= dp[cur][i];
	printf(ans ? "YES\n" : "NO\n");
}

Compilation message

bank.cpp: In function 'int main()':
bank.cpp:46:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&n,&m);
  ~~~~~^~~~~~~~~~~~~~~
bank.cpp:48:37: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 0 ; i < n ; i++) scanf("%d",&a[i]);
                                ~~~~~^~~~~~~~~~~~
bank.cpp:49:37: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 0 ; i < m ; i++) scanf("%d",&b[i]);
                                ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8568 KB Output is correct
2 Correct 14 ms 8692 KB Output is correct
3 Correct 14 ms 8692 KB Output is correct
4 Correct 15 ms 9016 KB Output is correct
5 Correct 30 ms 15348 KB Output is correct
6 Correct 14 ms 15348 KB Output is correct
7 Correct 14 ms 15348 KB Output is correct
8 Correct 31 ms 18324 KB Output is correct
9 Correct 29 ms 18324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 18324 KB Output is correct
2 Correct 25 ms 18324 KB Output is correct
3 Correct 25 ms 18324 KB Output is correct
4 Correct 28 ms 18324 KB Output is correct
5 Correct 38 ms 18324 KB Output is correct
6 Correct 31 ms 18324 KB Output is correct
7 Correct 26 ms 18324 KB Output is correct
8 Correct 30 ms 18324 KB Output is correct
9 Correct 27 ms 18324 KB Output is correct
10 Correct 30 ms 18324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 18324 KB Output is correct
2 Correct 25 ms 18324 KB Output is correct
3 Correct 47 ms 18324 KB Output is correct
4 Correct 57 ms 18324 KB Output is correct
5 Correct 48 ms 18324 KB Output is correct
6 Correct 32 ms 18324 KB Output is correct
7 Correct 32 ms 18324 KB Output is correct
8 Correct 29 ms 18324 KB Output is correct
9 Correct 40 ms 18324 KB Output is correct
10 Correct 40 ms 18324 KB Output is correct
11 Correct 56 ms 18324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8568 KB Output is correct
2 Correct 14 ms 8692 KB Output is correct
3 Correct 14 ms 8692 KB Output is correct
4 Correct 15 ms 9016 KB Output is correct
5 Correct 30 ms 15348 KB Output is correct
6 Correct 14 ms 15348 KB Output is correct
7 Correct 14 ms 15348 KB Output is correct
8 Correct 31 ms 18324 KB Output is correct
9 Correct 29 ms 18324 KB Output is correct
10 Correct 29 ms 18324 KB Output is correct
11 Correct 25 ms 18324 KB Output is correct
12 Correct 25 ms 18324 KB Output is correct
13 Correct 28 ms 18324 KB Output is correct
14 Correct 38 ms 18324 KB Output is correct
15 Correct 31 ms 18324 KB Output is correct
16 Correct 26 ms 18324 KB Output is correct
17 Correct 30 ms 18324 KB Output is correct
18 Correct 27 ms 18324 KB Output is correct
19 Correct 30 ms 18324 KB Output is correct
20 Correct 42 ms 18324 KB Output is correct
21 Correct 25 ms 18324 KB Output is correct
22 Correct 47 ms 18324 KB Output is correct
23 Correct 57 ms 18324 KB Output is correct
24 Correct 48 ms 18324 KB Output is correct
25 Correct 32 ms 18324 KB Output is correct
26 Correct 32 ms 18324 KB Output is correct
27 Correct 29 ms 18324 KB Output is correct
28 Correct 40 ms 18324 KB Output is correct
29 Correct 40 ms 18324 KB Output is correct
30 Correct 56 ms 18324 KB Output is correct
31 Correct 42 ms 22368 KB Output is correct
32 Correct 113 ms 22624 KB Output is correct
33 Correct 47 ms 22624 KB Output is correct
34 Correct 58 ms 22624 KB Output is correct
35 Correct 61 ms 22624 KB Output is correct
36 Correct 88 ms 22624 KB Output is correct
37 Correct 31 ms 22624 KB Output is correct
38 Correct 37 ms 22624 KB Output is correct
39 Correct 63 ms 22624 KB Output is correct
40 Correct 56 ms 22624 KB Output is correct
41 Correct 90 ms 22624 KB Output is correct
42 Correct 55 ms 22652 KB Output is correct
43 Correct 52 ms 22652 KB Output is correct
44 Correct 68 ms 22652 KB Output is correct
45 Correct 41 ms 22780 KB Output is correct
46 Correct 45 ms 22780 KB Output is correct
47 Correct 64 ms 22780 KB Output is correct
48 Correct 30 ms 22780 KB Output is correct
49 Correct 27 ms 22780 KB Output is correct
50 Correct 148 ms 22780 KB Output is correct
51 Correct 65 ms 22888 KB Output is correct
52 Correct 58 ms 22888 KB Output is correct
53 Correct 431 ms 22888 KB Output is correct
54 Correct 171 ms 22888 KB Output is correct
55 Correct 145 ms 22888 KB Output is correct
56 Correct 144 ms 22888 KB Output is correct
57 Correct 167 ms 22888 KB Output is correct
58 Correct 156 ms 22888 KB Output is correct