제출 #873782

#제출 시각아이디문제언어결과실행 시간메모리
873782Irate은행 (IZhO14_bank)C++14
71 / 100
1076 ms86616 KiB
#include<bits/stdc++.h> using namespace std; int n, m; vector<int>a, b; vector<int>sums; /// sums[i] -> sum of elements in the set i int dp[20][(1 << 20)]; bool rec(int indx, int mask){ bool res = 0; if(indx == n)return 1; if(dp[indx][mask] != -1)return dp[indx][mask]; for(int i = mask;i > 0; i = (i - 1) & mask){ if(sums[i] == a[indx]){ res |= rec(indx + 1, mask ^ i); } } return dp[indx][mask] = res; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; a.resize(n); b.resize(m); sums.resize((1 << m)); for(int i = 0;i < n;++i){ cin >> a[i]; } for(int i = 0;i < m;++i){ cin >> 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]; } } sums[i] = sum; } for(int i = 0;i < 20;++i){ for(int j = 0;j < (1 << 20);++j){ dp[i][j] = -1; } } if(rec(0, (1 << m) - 1)){ cout << "YES"; } else{ cout << "NO"; } }

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

bank.cpp: In function 'bool rec(int, int)':
bank.cpp:16:24: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   16 |  return dp[indx][mask] = res;
      |         ~~~~~~~~~~~~~~~^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...