Submission #396805

# Submission time Handle Problem Language Result Execution time Memory
396805 2021-04-30T18:55:57 Z SavicS Bank (IZhO14_bank) C++14
71 / 100
1000 ms 21184 KB
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
 
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define fb(i,b,a) for(int i=b;i>=a;i--)
 
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 21;
const int inf = 1e9 + 5;
 
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
// os.order_of_key(k) the number of elements in the os less than k
// *os.find_by_order(k)  print the k-th smallest number in os(0-based)
 
template <typename T> inline void read(T &x) {
	T f = 1;
	x = 0;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
	x *= f;
}
 
int n, m;
int A[maxn];
int B[maxn];
 
bool dp[21][(1 << 21)];
 
vector<int> koje[21];
 
int main()
{
    ios::sync_with_stdio(false);
    cout.tie(nullptr);
    cin.tie(nullptr);
    
	read(n), read(m);
	ff(i,0,n - 1)read(A[i]);
	ff(i,0,m - 1)read(B[i]);
	
	ff(mask,0,(1 << m) - 1){
		int sum = 0;
		ff(i,0,m - 1){
			if(mask & (1 << i))sum += B[i];
		}
		ff(i,0,n - 1){
			if(A[i] == sum)koje[i].pb(mask);
		}
	}
	
	dp[0][0] = 1;
	ff(i,0,n - 1){
		bool ok = 0;
		for(auto msk : koje[i]){
			int mask = msk ^ ((1 << m) - 1);
			// one koje mi ne trebaju da bi mogao da dobijem A[i]
			int smask = mask;
			while(1){
		
				// smask koristim za prosle i - 1
				// msk koristim za i
						
				dp[i + 1][msk | smask] |= dp[i][smask];
				if(dp[i + 1][msk | smask] == 1)ok = 1;
											
				if(smask == 0)break;			
					
				smask = (smask - 1) & mask;
			}
		}
		if(!ok)return cout << "NO", 0;
	}
	
	ff(mask,0,(1 << m) - 1){
		if(dp[n][mask] == 1)return cout << "YES", 0;
	}
	
	cout << "NO";
    return 0;
}
/**
 
1 5
8
4 2 5 1 3
 
// probati bojenje sahovski ili slicno
 
**/
 
# Verdict Execution time Memory Grader output
1 Correct 1 ms 436 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 3 ms 332 KB Output is correct
5 Correct 77 ms 312 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 85 ms 1392 KB Output is correct
9 Correct 69 ms 304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 460 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 2 ms 460 KB Output is correct
4 Correct 2 ms 204 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 2 ms 328 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 2 ms 460 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 436 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 3 ms 332 KB Output is correct
5 Correct 77 ms 312 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 85 ms 1392 KB Output is correct
9 Correct 69 ms 304 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 2 ms 460 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 2 ms 460 KB Output is correct
23 Correct 2 ms 204 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 2 ms 328 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 2 ms 332 KB Output is correct
28 Correct 2 ms 460 KB Output is correct
29 Correct 2 ms 460 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
31 Correct 79 ms 2112 KB Output is correct
32 Correct 219 ms 3572 KB Output is correct
33 Correct 97 ms 7356 KB Output is correct
34 Correct 90 ms 8764 KB Output is correct
35 Correct 94 ms 9652 KB Output is correct
36 Correct 115 ms 18248 KB Output is correct
37 Correct 68 ms 1344 KB Output is correct
38 Correct 73 ms 204 KB Output is correct
39 Correct 211 ms 8504 KB Output is correct
40 Correct 82 ms 4144 KB Output is correct
41 Correct 88 ms 1852 KB Output is correct
42 Correct 169 ms 5468 KB Output is correct
43 Correct 98 ms 7360 KB Output is correct
44 Correct 82 ms 316 KB Output is correct
45 Correct 107 ms 3396 KB Output is correct
46 Correct 104 ms 6456 KB Output is correct
47 Correct 124 ms 13380 KB Output is correct
48 Correct 101 ms 1348 KB Output is correct
49 Correct 67 ms 312 KB Output is correct
50 Correct 519 ms 21184 KB Output is correct
51 Correct 331 ms 10532 KB Output is correct
52 Correct 608 ms 10564 KB Output is correct
53 Execution timed out 1091 ms 10844 KB Time limit exceeded
54 Halted 0 ms 0 KB -