Submission #68452

# Submission time Handle Problem Language Result Execution time Memory
68452 2018-08-17T07:20:13 Z cdemirer Bank (IZhO14_bank) C++17
44 / 100
399 ms 94868 KB
#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef pair<double, double> dodo;
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)


int N, M;
int A[20], B[20];
unordered_map<int, int> table;
unordered_map<int, int> tblbits;

int main(int argc, char **argv) {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	cin >> N >> M;
	for (int i = 0; i < N; i++) cin >> A[i];
	sort(A, A+N);// reverse(A, A+N);
	for (int i = 0; i < M; i++) cin >> B[i];
	sort(B, B+M);// reverse(B, B+M);
	int mlim = 1<<M;
	int used = 0;
	for (int i = 0; i < N; i++) {
		bool flag = false;
		int best = mlim-1;
		int bestbits = 20;
		for (int m = mlim-1; m > 0; m--) {
			if (m & used) continue;
			if (!table[m]) {
				int sum = 0, bits = 0;
				for (int k = 0; k < M; k++) if (m & (1<<k)) sum += B[k], bits += 1;
				table[m] = sum;
				tblbits[m] = bits;
			}
			if (table[m] == A[i]) {
				flag = true;
				if (tblbits[m] < bestbits) {
					bestbits = tblbits[m];
					best = m;
				}
			}
		}
		if (!flag) {
			cout << "NO" << endl;
			return 0;
		}
		used |= best;
	}
	cout << "YES" << endl;
	

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 508 KB Output is correct
3 Correct 2 ms 656 KB Output is correct
4 Correct 12 ms 3248 KB Output is correct
5 Correct 386 ms 94848 KB Output is correct
6 Correct 2 ms 94848 KB Output is correct
7 Correct 2 ms 94848 KB Output is correct
8 Correct 399 ms 94848 KB Output is correct
9 Correct 391 ms 94868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 94868 KB Output is correct
2 Correct 2 ms 94868 KB Output is correct
3 Correct 2 ms 94868 KB Output is correct
4 Correct 2 ms 94868 KB Output is correct
5 Correct 2 ms 94868 KB Output is correct
6 Correct 2 ms 94868 KB Output is correct
7 Correct 2 ms 94868 KB Output is correct
8 Correct 2 ms 94868 KB Output is correct
9 Correct 2 ms 94868 KB Output is correct
10 Correct 2 ms 94868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 94868 KB Output is correct
2 Correct 7 ms 94868 KB Output is correct
3 Correct 7 ms 94868 KB Output is correct
4 Correct 7 ms 94868 KB Output is correct
5 Correct 7 ms 94868 KB Output is correct
6 Correct 7 ms 94868 KB Output is correct
7 Correct 7 ms 94868 KB Output is correct
8 Incorrect 7 ms 94868 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 508 KB Output is correct
3 Correct 2 ms 656 KB Output is correct
4 Correct 12 ms 3248 KB Output is correct
5 Correct 386 ms 94848 KB Output is correct
6 Correct 2 ms 94848 KB Output is correct
7 Correct 2 ms 94848 KB Output is correct
8 Correct 399 ms 94848 KB Output is correct
9 Correct 391 ms 94868 KB Output is correct
10 Correct 2 ms 94868 KB Output is correct
11 Correct 2 ms 94868 KB Output is correct
12 Correct 2 ms 94868 KB Output is correct
13 Correct 2 ms 94868 KB Output is correct
14 Correct 2 ms 94868 KB Output is correct
15 Correct 2 ms 94868 KB Output is correct
16 Correct 2 ms 94868 KB Output is correct
17 Correct 2 ms 94868 KB Output is correct
18 Correct 2 ms 94868 KB Output is correct
19 Correct 2 ms 94868 KB Output is correct
20 Correct 7 ms 94868 KB Output is correct
21 Correct 7 ms 94868 KB Output is correct
22 Correct 7 ms 94868 KB Output is correct
23 Correct 7 ms 94868 KB Output is correct
24 Correct 7 ms 94868 KB Output is correct
25 Correct 7 ms 94868 KB Output is correct
26 Correct 7 ms 94868 KB Output is correct
27 Incorrect 7 ms 94868 KB Output isn't correct
28 Halted 0 ms 0 KB -