Submission #933299

#TimeUsernameProblemLanguageResultExecution timeMemory
933299SmuggingSpunBank (IZhO14_bank)C++14
100 / 100
31 ms8736 KiB
#include<bits/stdc++.h> #define taskname "bank" using namespace std; const int lim = 20; int a[lim], b[lim], cnt[1 << lim], remain[1 << lim]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen(taskname".in", "r")){ freopen(taskname".in", "r", stdin); } int n, m; cin >> n >> m; for(int i = 0; i < n; i++){ cin >> a[i]; } for(int i = 0; i < m; i++){ cin >> b[i]; } memset(cnt, -1, sizeof(cnt)); remain[0] = a[cnt[0] = 0]; for(int mask = 1; mask < (1 << m); mask++){ int state = mask; while(state > 0){ int x = __builtin_ctz(state), index = cnt[mask ^ (1 << x)], left = remain[mask ^ (1 << x)]; if(index == -1 || b[x] > left){ state ^= 1 << x; continue; } if(b[x] == left){ if(index == n - 1){ return cout << "YES", 0; } remain[mask] = a[cnt[mask] = ++index]; } else{ remain[mask] = left - b[x]; cnt[mask] = index; } break; } } cout << "NO"; }

Compilation message (stderr)

bank.cpp: In function 'int main()':
bank.cpp:9:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |   freopen(taskname".in", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...