Submission #1085131

#TimeUsernameProblemLanguageResultExecution timeMemory
1085131pacmanBank (IZhO14_bank)C++17
0 / 100
2 ms348 KiB
#include <bits/stdc++.h> #define int long long int using namespace std; const int maxn = 1 << 21, inf = 1e18; int n, m, sallary[21],money[21], cover[maxn], left_money[maxn]; int32_t main(){ freopen("bank.in","r",stdin); freopen("bank.out","w",stdout); ios::sync_with_stdio(0) ,cout.tie(0) ,cin.tie(0); cin >> n >> m; for(int i = 0 ;i < n; i++){ cin >> sallary[i]; } for(int i = 0 ;i < m;i++){ cin >> money[i]; } for(int i = 0 ; i <= (1 << m); i++){ cover[i] = -inf; left_money[i] = -inf; } cover[0] = 0; left_money[0] = 0; for(int i = 0 ;i < (1 << m); i++){ int mask = i; while(mask > 0){ int j = __builtin_ctz(mask); int ghabli = i ^ (1 << j); if(cover[ghabli] == -inf){ mask ^= (1 << j); continue; } int now_money = left_money[ghabli] + money[j]; int want_money = sallary[cover[ghabli]]; if(now_money < want_money){ cover[i] = cover[ghabli]; left_money[i] = now_money; } else if(now_money == want_money){ cover[i] = cover[ghabli] + 1; left_money[i] = 0; } mask ^= (1 << j); } if(cover[i] == n){ cout << "YES" << endl; return 0; } } cout << "NO" << endl; return 0; }

Compilation message (stderr)

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