Submission #684133

#TimeUsernameProblemLanguageResultExecution timeMemory
684133kussssoBank (IZhO14_bank)C++17
100 / 100
567 ms179036 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; const int N = 21; int n, m; int a[N]; int b[N]; vector<int> g[1005]; int dp[1 << N][N]; int cal (int t, int i) { if (i == n - 1) { return 1; } int &res = dp[t][i + 1]; if (res != -1) return res; res = 0; for (auto& nt : g[a[i + 1]]) { if ((nt & t) == 0) { res |= cal(t | nt, i + 1); } } return res; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); #define TN "bank" if (ifstream(TN".in")) { freopen(TN".in", "r", stdin); freopen(TN".out", "w", stdout); } 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 t = 0; t < (1 << m); t++) { int sum = 0; for (int i = 0; i < m; i++) { sum += ((t >> i) & 1) * b[i]; } if (sum <= 1000) { g[sum].push_back(t); } } memset(dp, -1, sizeof dp); cout << (cal(0, -1) ? "YES" : "NO"); return 0; }

Compilation message (stderr)

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