제출 #1087796

#제출 시각아이디문제언어결과실행 시간메모리
1087796quangminh412은행 (IZhO14_bank)C++14
19 / 100
61 ms1116 KiB
#include <bits/stdc++.h> using namespace std; /* John Watson https://codeforces.com/profile/quangminh98 Mua Code nhu mua Florentino !! */ #define faster() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define ll long long const int maxn = 30; int n, m; int a[maxn], b[maxn]; void solve_1() { 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]; if (sum == a[1]) { cout << "YES\n"; return; } } cout << "NO\n"; } signed main() { if (fopen("test.inp", "r")) { freopen("test.inp", "r", stdin); freopen("test.out", "w", stdout); } faster(); cin >> n >> m; int full = (1 << m); for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= m; i++) cin >> b[i]; if (n == 1) { solve_1(); return 0; } vector<vector<int>> dp(n + 5, vector<int>(full + 5, 0)); // base case for (int mask = 0; mask < full; mask++) { int sum = 0; for (int i = 0; i < m; i++) if (mask >> i & 1) sum += b[i]; if (sum == a[1]) dp[1][mask] = 1; } // for (int i = 2; i <= n; i++) { for (int mask1 = 0; mask1 < full; mask1++) if (dp[i - 1][mask1]) { for (int mask2 = 0; mask2 < full; mask2++) if ((mask1 & mask2) == 0) { int sum = 0; for (int j = 0; j < m; j++) if (mask2 >> j & 1) sum += b[j]; if (sum == a[i]) dp[i][mask1 | mask2] = 1; } } } int ans = 0; for (int mask = 0; mask < full; mask++) ans = max(ans, dp[n][mask]); cout << (ans == 0 ? "NO\n" : "YES\n"); return 0; }

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

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