제출 #1088202

#제출 시각아이디문제언어결과실행 시간메모리
1088202T0p_은행 (IZhO14_bank)C++14
100 / 100
172 ms94504 KiB
#include <bits/stdc++.h>
using namespace std;

const int N = 20;

int a[N], b[N], dp[N+1][1<<N];
vector<int> sum_to_bit[20001];

int solve(int n, int s) {
  if (dp[n][s] != -1) {
    return dp[n][s];
  }

  if (n == 0) {
    return dp[n][s] = 1;
  }

  int res = 0;
  for (int bit : sum_to_bit[a[n-1]]) {
    if ((bit & s) == bit) {
      res |= solve(n-1, bit ^ s);
    }
  }

  return dp[n][s] = res;
}

int main() {
  int n, m;
  scanf(" %d %d", &n, &m);

  for (int i=0 ; i<n ; i++) {
    scanf(" %d", &a[i]);
  }

  for (int i=0 ; i<m ; i++) {
    scanf(" %d", &b[i]);
  }

  for (int i=0 ; i<1<<m ; i++) {
    int sum = 0;
    for (int j=0 ; j<m ; j++) {
      if (i & (1<<j)) {
        sum += b[j];
      }
    }

    sum_to_bit[sum].push_back(i);
  }

  memset(dp, -1, sizeof(dp));

  printf(solve(n, (1<<m)-1) == 1 ? "YES\n" : "NO\n");
  return 0;
}

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

bank.cpp: In function 'int main()':
bank.cpp:30:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |   scanf(" %d %d", &n, &m);
      |   ~~~~~^~~~~~~~~~~~~~~~~~
bank.cpp:33:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     scanf(" %d", &a[i]);
      |     ~~~~~^~~~~~~~~~~~~~
bank.cpp:37:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |     scanf(" %d", &b[i]);
      |     ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...