Submission #88430

# Submission time Handle Problem Language Result Execution time Memory
88430 2018-12-05T21:31:17 Z xiaowuc1 Divide and conquer (IZhO14_divide) C++14
0 / 100
2 ms 432 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n, m;
int val[20];
int bases[20];
vector<int> masks[1001];
void solve() {
  cin >> n >> m;
  for(int i = 0; i < n; i++) cin >> val[i];
  sort(val, val+n);
  reverse(val, val+n);
  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> ret;
  ret.insert(0);
  for(int i = 0; i < n; i++) {
    unordered_set<int> nret;
    for(int out2: ret) {
      for(int out: masks[val[i]]) {
        if(out&out2) continue;
        if(__builtin_popcount(out | out2) + (n-i-1) > m) continue;
        nret.insert(out | out2);
      }
    }
    ret = nret;
  }
  if(ret.empty()) cout << "NO\n";
  else cout << "YES\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 432 KB Output isn't correct
2 Halted 0 ms 0 KB -