제출 #716633

#제출 시각아이디문제언어결과실행 시간메모리
716633nonono은행 (IZhO14_bank)C++14
100 / 100
72 ms8532 KiB
#include "bits/stdc++.h" #define SZ(x) (int)(x.size()) using namespace std; const int mxN = 20; int n, m, a[mxN], b[mxN]; pair<int, int> dp[1 << mxN]; signed main(){ #define name "bank" if(fopen(name".inp", "r")){ freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); } ios_base::sync_with_stdio(); cin.tie(); cout.tie(); cin >> n >> m; for(int i = 0; i < n; i ++) cin >> a[i]; for(int i = 0; i < m; i ++) cin >> b[i]; for(int mask = 0; mask < (1 << m); mask ++) dp[mask] = {-1, 0}; dp[0] = {0, 0}; for(int mask = 0; mask < (1 << m); mask ++){ for(int x = mask; x > 0; x ^= x & (- x)){ int i = __builtin_ctz(x & (- x)); int nmask = mask ^ (1 << i); if(dp[nmask].first == -1) continue ; int j = dp[nmask].first; if(dp[nmask].second + b[i] < a[j]) dp[mask] = {j, dp[nmask].second + b[i]}; if(dp[nmask].second + b[i] == a[j]) dp[mask] = {j + 1, 0}; if(dp[mask].first == n){ cout << "YES\n"; exit(0); } } } cout << "NO\n"; return 0; }

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

bank.cpp: In function 'int main()':
bank.cpp:12:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |         freopen(name".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:13:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |         freopen(name".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...