Submission #917819

#TimeUsernameProblemLanguageResultExecution timeMemory
917819KactusJackBank (IZhO14_bank)C++17
0 / 100
2 ms604 KiB
#include<bits/stdc++.h> #define ll long long #define F first #define S second using namespace std; int n, m; vector<int> a, b, sum, prefix; vector<vector<int>> mem; int dp(int i, int mask){ if(i == n){ return 1; } int &ret = mem[i][mask]; if(ret != -1){ return ret; } ret = 0; int rest = prefix[i] - sum[mask]; if(rest == 0){ ret = dp(i+1, mask); } else{ for(int j = 0; j < m; j++){ if(!(mask&(1<<j)) && b[j] <= rest){ ret = max(ret, dp(i, mask^(1<<j))); } } } return ret; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); freopen("bank.in", "r", stdin); freopen("bank.out", "w", stdout); cin >> n >> m; a = vector<int> (n); for(int i = 0; i < n; i++){ cin >> a[i]; } b = vector<int> (m); for(int i = 0; i < m; i++){ cin >> b[i]; } prefix = vector<int> (n); prefix[0] = a[0]; for(int i = 1; i < n; i++){ prefix[i] = prefix[i-1] + a[i]; } sum = vector<int> (1<<m); for(int mask = 0; mask < (1<<m); mask++){ for(int i = 0; i < m; i++){ if((mask&(1<<i))){ sum[mask] += b[i]; } } } mem = vector<vector<int>> (n, vector<int> (1<<m, -1)); cout << (dp(0, 0) ? "YES" : "NO") << '\n'; return 0; }

Compilation message (stderr)

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