# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
88438 |
2018-12-05T21:50:23 Z |
xiaowuc1 |
Bank (IZhO14_bank) |
C++14 |
|
1000 ms |
13352 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, m;
int bases[20];
vector<int> masks[1001];
void analyze(unordered_set<int>& lhs, unordered_set<int>& rhs) {
for(int out: lhs) {
int mask = -1+(1<<m)-out;
for(int t = mask; t >= 0; t--) {
t &= mask;
if(rhs.count(t)) {
cout << "YES\n";
exit(0);
}
}
}
}
unordered_set<int> solve(vector<int> v, int leftover) {
unordered_set<int> ret;
ret.insert(0);
for(int i = 0; i < v.size(); i++) {
unordered_set<int> nret;
for(int out2: ret) {
for(int out: masks[v[i]]) {
if(out&out2) continue;
if(__builtin_popcount(out | out2) + (leftover + v.size()-i-1) > m) continue;
nret.insert(out | out2);
}
}
ret = nret;
}
return ret;
}
void solve() {
cin >> n >> m;
vector<int> a, b;
{
vector<int> values;
for(int i = 0; i < n; i++) {
int t;
cin >> t;
values.push_back(t);
}
sort(values.begin(), values.end());
for(int i = 0; i < n; i++) {
(i < n/2 ? a : b).push_back(values[i]);
}
}
for(int i = 0; i < m; i++) cin >> bases[i];
for(int mask = 1; mask < (1<<m); mask++) {
int v = 0;
int t = mask;
while(v <= 1000 && t) {
v += bases[__builtin_ctz(t)];
t &= t-1;
}
if(v <= 1000) masks[v].push_back(mask);
}
unordered_set<int> reta = solve(a, b.size());
unordered_set<int> retb = solve(b, a.size());
if(reta.size() > retb.size()) {
analyze(retb, reta);
}
else {
analyze(reta, retb);
}
for(int outa: reta) {
for(int outb: retb) {
if((outa&outb) == 0) {
cout << "YES\n";
return;
}
}
}
cout << "NO\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
solve();
}
Compilation message
bank.cpp: In function 'std::unordered_set<int> solve(std::vector<int>, int)':
bank.cpp:27:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < v.size(); i++) {
~~^~~~~~~~~~
bank.cpp:32:71: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(__builtin_popcount(out | out2) + (leftover + v.size()-i-1) > m) continue;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
476 KB |
Output is correct |
4 |
Correct |
3 ms |
612 KB |
Output is correct |
5 |
Correct |
27 ms |
6800 KB |
Output is correct |
6 |
Correct |
2 ms |
6800 KB |
Output is correct |
7 |
Correct |
2 ms |
6800 KB |
Output is correct |
8 |
Correct |
26 ms |
6800 KB |
Output is correct |
9 |
Correct |
25 ms |
6800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6800 KB |
Output is correct |
2 |
Correct |
2 ms |
6800 KB |
Output is correct |
3 |
Correct |
2 ms |
6800 KB |
Output is correct |
4 |
Correct |
2 ms |
6800 KB |
Output is correct |
5 |
Correct |
2 ms |
6800 KB |
Output is correct |
6 |
Correct |
2 ms |
6800 KB |
Output is correct |
7 |
Correct |
2 ms |
6800 KB |
Output is correct |
8 |
Correct |
2 ms |
6800 KB |
Output is correct |
9 |
Correct |
2 ms |
6800 KB |
Output is correct |
10 |
Correct |
2 ms |
6800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6800 KB |
Output is correct |
2 |
Correct |
2 ms |
6800 KB |
Output is correct |
3 |
Correct |
2 ms |
6800 KB |
Output is correct |
4 |
Correct |
2 ms |
6800 KB |
Output is correct |
5 |
Correct |
2 ms |
6800 KB |
Output is correct |
6 |
Correct |
2 ms |
6800 KB |
Output is correct |
7 |
Correct |
2 ms |
6800 KB |
Output is correct |
8 |
Correct |
2 ms |
6800 KB |
Output is correct |
9 |
Correct |
2 ms |
6800 KB |
Output is correct |
10 |
Correct |
2 ms |
6800 KB |
Output is correct |
11 |
Correct |
2 ms |
6800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
476 KB |
Output is correct |
4 |
Correct |
3 ms |
612 KB |
Output is correct |
5 |
Correct |
27 ms |
6800 KB |
Output is correct |
6 |
Correct |
2 ms |
6800 KB |
Output is correct |
7 |
Correct |
2 ms |
6800 KB |
Output is correct |
8 |
Correct |
26 ms |
6800 KB |
Output is correct |
9 |
Correct |
25 ms |
6800 KB |
Output is correct |
10 |
Correct |
2 ms |
6800 KB |
Output is correct |
11 |
Correct |
2 ms |
6800 KB |
Output is correct |
12 |
Correct |
2 ms |
6800 KB |
Output is correct |
13 |
Correct |
2 ms |
6800 KB |
Output is correct |
14 |
Correct |
2 ms |
6800 KB |
Output is correct |
15 |
Correct |
2 ms |
6800 KB |
Output is correct |
16 |
Correct |
2 ms |
6800 KB |
Output is correct |
17 |
Correct |
2 ms |
6800 KB |
Output is correct |
18 |
Correct |
2 ms |
6800 KB |
Output is correct |
19 |
Correct |
2 ms |
6800 KB |
Output is correct |
20 |
Correct |
2 ms |
6800 KB |
Output is correct |
21 |
Correct |
2 ms |
6800 KB |
Output is correct |
22 |
Correct |
2 ms |
6800 KB |
Output is correct |
23 |
Correct |
2 ms |
6800 KB |
Output is correct |
24 |
Correct |
2 ms |
6800 KB |
Output is correct |
25 |
Correct |
2 ms |
6800 KB |
Output is correct |
26 |
Correct |
2 ms |
6800 KB |
Output is correct |
27 |
Correct |
2 ms |
6800 KB |
Output is correct |
28 |
Correct |
2 ms |
6800 KB |
Output is correct |
29 |
Correct |
2 ms |
6800 KB |
Output is correct |
30 |
Correct |
2 ms |
6800 KB |
Output is correct |
31 |
Correct |
27 ms |
6800 KB |
Output is correct |
32 |
Correct |
87 ms |
6800 KB |
Output is correct |
33 |
Correct |
17 ms |
6800 KB |
Output is correct |
34 |
Correct |
7 ms |
6800 KB |
Output is correct |
35 |
Correct |
7 ms |
6800 KB |
Output is correct |
36 |
Correct |
8 ms |
6800 KB |
Output is correct |
37 |
Correct |
12 ms |
6800 KB |
Output is correct |
38 |
Correct |
14 ms |
6800 KB |
Output is correct |
39 |
Correct |
29 ms |
6800 KB |
Output is correct |
40 |
Correct |
20 ms |
6800 KB |
Output is correct |
41 |
Correct |
17 ms |
6800 KB |
Output is correct |
42 |
Correct |
53 ms |
6800 KB |
Output is correct |
43 |
Correct |
22 ms |
6800 KB |
Output is correct |
44 |
Correct |
6 ms |
6800 KB |
Output is correct |
45 |
Correct |
29 ms |
6800 KB |
Output is correct |
46 |
Correct |
25 ms |
6800 KB |
Output is correct |
47 |
Correct |
7 ms |
6800 KB |
Output is correct |
48 |
Correct |
26 ms |
6800 KB |
Output is correct |
49 |
Correct |
25 ms |
6800 KB |
Output is correct |
50 |
Correct |
118 ms |
7976 KB |
Output is correct |
51 |
Correct |
49 ms |
7976 KB |
Output is correct |
52 |
Correct |
353 ms |
8784 KB |
Output is correct |
53 |
Execution timed out |
1082 ms |
13352 KB |
Time limit exceeded |
54 |
Halted |
0 ms |
0 KB |
- |