제출 #1088199

#제출 시각아이디문제언어결과실행 시간메모리
1088199T0p_은행 (IZhO14_bank)C++14
71 / 100
1068 ms8276 KiB
#include <bits/stdc++.h> using namespace std; const int N = 20; int a[N], b[N]; bool dp[N][1<<N]; vector<int> sum_to_bit[20001]; bool solve(int n, int s) { if (n == 0) { return true; } bool res = false; for (int bit : sum_to_bit[a[n-1]]) { if ((bit & s) == bit) { res |= solve(n-1, bit ^ s); } } return 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); } printf(solve(n, (1<<m)-1) ? "YES\n" : "NO\n"); return 0; }

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

bank.cpp: In function 'int main()':
bank.cpp:27:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |   scanf(" %d %d", &n, &m);
      |   ~~~~~^~~~~~~~~~~~~~~~~~
bank.cpp:30:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     scanf(" %d", &a[i]);
      |     ~~~~~^~~~~~~~~~~~~~
bank.cpp:34:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |     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...