Submission #1131243

#TimeUsernameProblemLanguageResultExecution timeMemory
1131243catsarecool5530Bank (IZhO14_bank)C++20
0 / 100
2 ms324 KiB
//#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; using ll = long long; // #define endl "\n"; #define all(x) x.begin(), x.end() ll MOD = 1e9+7; struct Obj { int used, soFar; }; void solve() { int n, m; cin >> n >> m; if (n > m) { cout << "NO\n"; return; } vector<ll> people(n); for (ll& i : people) { cin >> i; } vector<ll> money(m); for (ll& i : money) { cin >> i; } vector<Obj> dp((1 << m), {-1, -1}); dp[0] = {0, 0}; for (int mask = 0; mask < (1 << m); mask++) { if (dp[mask].used == -1) continue; if (dp[mask].used == n) { cout << "YES\n"; return; } for (int i = 0; i < m; i++) { //cerr << mask << ' ' << i << endl; if (mask & (1 << i)) continue; ll newMask = mask | (1 << i); if (money[i] + dp[mask].soFar > people[dp[mask].used]) { continue; } if (money[i] + dp[mask].soFar == people[dp[mask].used]) { dp[newMask] = {dp[mask].used + 1, 0}; } else { dp[newMask] = {dp[mask].used, money[i] + dp[mask].soFar}; } } } cout << "NO\n"; } int main() { ios::sync_with_stdio(0); cin.tie(0); freopen("bank.in", "r", stdin); freopen("bank.out", "w", stdout); ll t = 1; //cin >> t; while (t--) { solve(); } }

Compilation message (stderr)

bank.cpp: In function 'void solve()':
bank.cpp:46:72: warning: narrowing conversion of '(money.std::vector<long long int>::operator[](((std::vector<long long int>::size_type)i)) + ((__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type)dp.std::vector<Obj>::operator[](((std::vector<Obj>::size_type)mask)).Obj::soFar))' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
   46 |                                 dp[newMask] = {dp[mask].used, money[i] + dp[mask].soFar};
bank.cpp: In function 'int main()':
bank.cpp:56:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |         freopen("bank.in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:57:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |         freopen("bank.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...