제출 #652550

#제출 시각아이디문제언어결과실행 시간메모리
652550chanhchuong123은행 (IZhO14_bank)C++14
100 / 100
185 ms82508 KiB
#include <bits/stdc++.h>
using namespace std;
#define task "C"
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

template <typename T1, typename T2> bool mini(T1 &a, T2 b) {
  if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maxi(T1 &a, T2 b) {
  if (a < b) {a = b; return true;} return false;
}

int n, m;
int a[20], b[20];
int dp[20][1 << 20];
vector<int> MASK[20];

bool DP(int i, int mask) {
  if (i < 0) {
    cout << "YES";
    exit(0);
  }
  if (dp[i][mask] > -1) return dp[i][mask];
  int ans = 0;
  for (int state: MASK[i]) {
    if (state & mask) continue;
    ans |= DP(i - 1, mask | state);
  }
  return dp[i][mask] = ans;
}

main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);

  if (fopen(task".inp","r")) {
    freopen(task".inp","r",stdin);
    freopen(task".out","w",stdout);
  }

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

  if (accumulate(a, a + n, 0) > accumulate(b, b + m, 0)) {
    cout << "NO"; exit(0);
  }
  for (int mask = 0; mask < (1 << m); mask++) {
    int sum = 0;
    for (int i = 0; i < m; i++)
      if (mask >> i & 1) sum += b[i];
    for (int i = 0; i < n; i++)
      if (sum == a[i]) MASK[i].push_back(mask);
  }
  memset(dp, -1, sizeof(dp));
  DP(n - 1, 0); cout << "NO";
  //cout << (DP(n - 1, 0) ? "YES" : "NO");
}

컴파일 시 표준 에러 (stderr) 메시지

bank.cpp: In function 'bool DP(int, int)':
bank.cpp:32:22: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   32 |   return dp[i][mask] = ans;
      |          ~~~~~~~~~~~~^~~~~
bank.cpp: At global scope:
bank.cpp:35:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   35 | main() {
      | ^~~~
bank.cpp: In function 'int main()':
bank.cpp:40:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |     freopen(task".inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
bank.cpp:41:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |     freopen(task".out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...