Submission #555809

#TimeUsernameProblemLanguageResultExecution timeMemory
555809AlmaBank (IZhO14_bank)C++17
46 / 100
99 ms8500 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 idx[(1 << 20)], dp[(1 << 20)]; int main() { setIO("std"); memset(pre, 0, sizeof pre); memset(dp, -1, sizeof dp); dp[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 mask = 1; mask < (1 << M); mask++) { for (int i = 0; i < M; i++) { if (!(mask & (1 << i))) continue; int x = mask - (1 << i); if (dp[x] == pre[idx[x]]) { dp[mask] = dp[x] + b[i]; idx[mask] = idx[x] + 1; } else if (dp[x] != -1 and dp[x] + b[i] <= pre[idx[x]]) { dp[mask] = dp[x] + b[i]; idx[mask] = idx[x]; } } } for (int mask = 0; mask < (1 << M); mask++) { if (dp[mask] == pre[N-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...