Submission #1269472

#TimeUsernameProblemLanguageResultExecution timeMemory
1269472quangminh412Bank (IZhO14_bank)C++17
100 / 100
100 ms16852 KiB
/* Ben Watson Quang Minh MasterDDDDD */ #include <bits/stdc++.h> using namespace std; #define ll long long const string name = "test"; void solve(); signed main() { if (fopen((name + ".inp").c_str(), "r")) { freopen((name + ".inp").c_str(), "r", stdin); freopen((name + ".out").c_str(), "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); return 0; } // main program const int maxn = 21; const int maxbit = (1 << maxn); int cover[maxbit], leftover[maxbit]; int a[maxn], b[maxn]; int n, m; void solve() { cin >> n >> m; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= m; i++) cin >> b[i]; memset(cover, -1, sizeof(cover)); memset(leftover, -1, sizeof(leftover)); cover[0] = 0; leftover[0] = 0; for (int mask = 0; mask < (1 << m); mask++) { for (int i = 0; i < m; i++) { if (!(mask >> i & 1)) continue; int prev = (mask ^ (1 << i)); if (cover[prev] == -1) continue; int new_leftover = leftover[prev] + b[i + 1]; int idx = cover[prev] + 1; if (new_leftover < a[idx]) { cover[mask] = cover[prev]; leftover[mask] = new_leftover; } else if (new_leftover == a[idx]) { cover[mask] = idx; leftover[mask] = 0; } } if (cover[mask] == n) { cout << "YES\n"; return; } } cout << "NO\n"; }

Compilation message (stderr)

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