Submission #88439

# Submission time Handle Problem Language Result Execution time Memory
88439 2018-12-05T21:51:01 Z xiaowuc1 Bank (IZhO14_bank) C++14
71 / 100
1000 ms 15708 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

mt19937 g1;

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);
    }
    shuffle(values.begin(), values.end(), g1);
    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:29:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < v.size(); i++) {
                  ~~^~~~~~~~~~
bank.cpp:34: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 380 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 576 KB Output is correct
4 Correct 2 ms 640 KB Output is correct
5 Correct 26 ms 6656 KB Output is correct
6 Correct 2 ms 6656 KB Output is correct
7 Correct 2 ms 6656 KB Output is correct
8 Correct 26 ms 6656 KB Output is correct
9 Correct 24 ms 6656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6656 KB Output is correct
2 Correct 2 ms 6656 KB Output is correct
3 Correct 2 ms 6656 KB Output is correct
4 Correct 2 ms 6656 KB Output is correct
5 Correct 2 ms 6656 KB Output is correct
6 Correct 2 ms 6656 KB Output is correct
7 Correct 2 ms 6656 KB Output is correct
8 Correct 2 ms 6656 KB Output is correct
9 Correct 2 ms 6656 KB Output is correct
10 Correct 2 ms 6656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6656 KB Output is correct
2 Correct 2 ms 6656 KB Output is correct
3 Correct 2 ms 6656 KB Output is correct
4 Correct 2 ms 6656 KB Output is correct
5 Correct 2 ms 6656 KB Output is correct
6 Correct 2 ms 6656 KB Output is correct
7 Correct 2 ms 6656 KB Output is correct
8 Correct 2 ms 6656 KB Output is correct
9 Correct 2 ms 6656 KB Output is correct
10 Correct 2 ms 6656 KB Output is correct
11 Correct 2 ms 6656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 576 KB Output is correct
4 Correct 2 ms 640 KB Output is correct
5 Correct 26 ms 6656 KB Output is correct
6 Correct 2 ms 6656 KB Output is correct
7 Correct 2 ms 6656 KB Output is correct
8 Correct 26 ms 6656 KB Output is correct
9 Correct 24 ms 6656 KB Output is correct
10 Correct 2 ms 6656 KB Output is correct
11 Correct 2 ms 6656 KB Output is correct
12 Correct 2 ms 6656 KB Output is correct
13 Correct 2 ms 6656 KB Output is correct
14 Correct 2 ms 6656 KB Output is correct
15 Correct 2 ms 6656 KB Output is correct
16 Correct 2 ms 6656 KB Output is correct
17 Correct 2 ms 6656 KB Output is correct
18 Correct 2 ms 6656 KB Output is correct
19 Correct 2 ms 6656 KB Output is correct
20 Correct 2 ms 6656 KB Output is correct
21 Correct 2 ms 6656 KB Output is correct
22 Correct 2 ms 6656 KB Output is correct
23 Correct 2 ms 6656 KB Output is correct
24 Correct 2 ms 6656 KB Output is correct
25 Correct 2 ms 6656 KB Output is correct
26 Correct 2 ms 6656 KB Output is correct
27 Correct 2 ms 6656 KB Output is correct
28 Correct 2 ms 6656 KB Output is correct
29 Correct 2 ms 6656 KB Output is correct
30 Correct 2 ms 6656 KB Output is correct
31 Correct 26 ms 6656 KB Output is correct
32 Correct 79 ms 6756 KB Output is correct
33 Correct 16 ms 6756 KB Output is correct
34 Correct 7 ms 6756 KB Output is correct
35 Correct 7 ms 6756 KB Output is correct
36 Correct 8 ms 6756 KB Output is correct
37 Correct 12 ms 6756 KB Output is correct
38 Correct 14 ms 6756 KB Output is correct
39 Correct 29 ms 6756 KB Output is correct
40 Correct 22 ms 6756 KB Output is correct
41 Correct 18 ms 6756 KB Output is correct
42 Correct 60 ms 6756 KB Output is correct
43 Correct 22 ms 6756 KB Output is correct
44 Correct 7 ms 6756 KB Output is correct
45 Correct 26 ms 6780 KB Output is correct
46 Correct 25 ms 6780 KB Output is correct
47 Correct 7 ms 6780 KB Output is correct
48 Correct 25 ms 6780 KB Output is correct
49 Correct 24 ms 6780 KB Output is correct
50 Correct 97 ms 7968 KB Output is correct
51 Correct 40 ms 7968 KB Output is correct
52 Correct 252 ms 9228 KB Output is correct
53 Correct 868 ms 15708 KB Output is correct
54 Correct 179 ms 15708 KB Output is correct
55 Correct 97 ms 15708 KB Output is correct
56 Correct 195 ms 15708 KB Output is correct
57 Execution timed out 1084 ms 15708 KB Time limit exceeded
58 Halted 0 ms 0 KB -