Submission #794963

#TimeUsernameProblemLanguageResultExecution timeMemory
794963nguyennehehe은행 (IZhO14_bank)C++14
Compilation error
0 ms0 KiB
#include<bits/stdc++.h>
using namespace std;

const int N = 20;

int n, m, a[N], b[N];

void sub1() {
  bool ok = false;
  for (int s = 1; s < (1 << m); ++s) {
    int sum = 0;
    for (int i = 0; i < m; ++i) {
      if (s >> i & 1) sum += b[i];
    }

    ok |= sum == a[0];
  }

  cout << (ok ? "YES" : "NO");
}

void sub2() {
  bool good = false;
  sort(b, b + m);
  do {
    bool ok = true;
    for (int i = 0, j = 0; i < n; ++i) {
      int sum = 0;
      while (j < m && sum < a[i]) {
        sum += b[j];
        j += 1;
      }
      ok &= sum == a[i];
    }
    good |= ok;

    if (good) break;
  } while (next_permutation(b, b + m));
  cout << (good ? "YES": "NO");
}

void maximize(int &x, int y) {
  if (x < y) x = y;
}

void sub3() {
  vector<int> sum(1 << m);
  for (int s = 1; s < (1 << m); ++s) {
    int cur = 0;
    for (int i = 0; i < m; ++i) {
      if (s >> i & 1) cur += b[i];
    }
    sum[s] = cur;
  }
  vector dp(n, vector<int>(1 << m));
  for (int s = 0; s < (1 << m); ++s) {
    if (sum[s] == a[0]) dp[0][s] = 1;
  }
  for (int i = 1; i < n; ++i) {
    for (int s = 0; s < (1 << m); ++s) {
      int msk = ((1 << m) - 1) ^ s;
      for (int x = msk; ; x = (x - 1) & msk) {
        if (sum[x] == a[i]) {
          maximize(dp[i][s], dp[i - 1][x] + 1);
        }
        else {
          dp[i][x] = dp[i - 1][x];
        }

        if (x == 0) break;
      }
    }
  }
  bool good = false;
  for (int s = 0; s < (1 << m); ++s) {
    if (dp[n - 1][s] == n) good = true;
  }
  cout << (good ? "YES": "NO");
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  cin >> n >> m;
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < m; ++i) cin >> b[i];
  sub3();
}

Compilation message (stderr)

bank.cpp: In function 'void sub3()':
bank.cpp:55:10: error: missing template arguments before 'dp'
   55 |   vector dp(n, vector<int>(1 << m));
      |          ^~
bank.cpp:57:25: error: 'dp' was not declared in this scope
   57 |     if (sum[s] == a[0]) dp[0][s] = 1;
      |                         ^~
bank.cpp:64:20: error: 'dp' was not declared in this scope
   64 |           maximize(dp[i][s], dp[i - 1][x] + 1);
      |                    ^~
bank.cpp:67:11: error: 'dp' was not declared in this scope
   67 |           dp[i][x] = dp[i - 1][x];
      |           ^~
bank.cpp:76:9: error: 'dp' was not declared in this scope
   76 |     if (dp[n - 1][s] == n) good = true;
      |         ^~