Submission #555802

#TimeUsernameProblemLanguageResultExecution timeMemory
555802AlmaBank (IZhO14_bank)C++17
0 / 100
39 ms82388 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second using ll = long long; using ii = pair<int,int>; const int INF = 1e9; const ll LLINF = 1e18; using vi = vector<int>; using vvi = vector<vi>; void setIO (string fileName) { ios::sync_with_stdio(false); cin.tie(NULL); if (fileName != "std") { freopen((fileName + ".in").c_str(), "r", stdin); freopen((fileName + ".out").c_str(), "w", stdout); } } int N, M; int a[20], b[20], pre[20]; int dp[20][1 << 20]; int main() { setIO("std"); memset(pre, 0, sizeof pre); memset(dp, -1, sizeof dp); dp[0][0] = 0; cin >> N >> M; for (int i = 0; i < N; i++) { cin >> a[i]; if (i == 0) pre[i] = a[i]; else pre[i] = a[i] + pre[i-1]; } for (int i = 0; i < M; i++) { cin >> b[i]; } for (int i = 0; i < N; i++) { for (int mask = 0; mask < (1 << N); mask++) { for (int p = 0; p < N; p++) { if (!(mask & (1 << p))) continue; int x = mask - (1 << p); if (i > 0 and dp[i-1][x] == pre[i-1]) dp[i][mask] = dp[i-1][x] + b[p]; if (dp[i][x] != -1) dp[i][mask] = dp[i][x] + b[p]; } } } for (int mask = 0; mask < (1 << N); mask++) { if (dp[N-1][mask] != -1) { cout << "YES\n"; return 0; } } cout << "NO\n"; return 0; }

Compilation message (stderr)

bank.cpp: In function 'void setIO(std::string)':
bank.cpp:18:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         freopen((fileName + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:19:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         freopen((fileName + ".out").c_str(), "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...