Submission #651480

#TimeUsernameProblemLanguageResultExecution timeMemory
651480quocnguyen1012Bank (IZhO14_bank)C++14
100 / 100
129 ms8540 KiB
#include "bits/stdc++.h"

using namespace std;

string to_string(string s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
template<class T>  bool maximize(T &x, T y) {
  if (x <= y) {
    x = y; return true;
  }
  return false;
}

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  if (fopen("input.txt", "r")) freopen("input.txt", "r", stdin);

  int n, m; cin >> n >> m;
  vector<int> a(n), b(m), f(1 << m), g(1 << m);
  for (auto&i : a) cin >> i, cerr << i << ' ';
  for (auto&i : b) cin >> i;
  //debug(n, m);
  for (int mask = 0; mask < (1 << m); ++mask) {
    for (int i = 0; i < m; ++i) {
      if (mask >> i & 1) {
        if (maximize(f[mask], f[mask ^ (1 << i)])) {
          g[mask] = g[mask ^ (1 << i)] + b[i];
        }
        //debug(mask, f[mask], g[mask ^ (1 << i));
        if (g[mask ^ (1 << i)] + b[i] == a[f[mask ^ (1 << i)]]) {
          if (maximize(f[mask], f[mask ^ (1 << i)] + 1)) {
            f[mask] = f[mask ^ (1 << i)] + 1;
            g[mask] = 0;
          }
        }
      }
    }
    if (f[mask] == n) {
      cout << "YES\n";
      return 0;
    }
  }
  cout << "NO\n";
}

Compilation message (stderr)

bank.cpp: In function 'int main()':
bank.cpp:59:39: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |   if (fopen("input.txt", "r")) freopen("input.txt", "r", stdin);
      |                                ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...