Submission #869961

#TimeUsernameProblemLanguageResultExecution timeMemory
869961TimAniBank (IZhO14_bank)C++17
52 / 100
1068 ms79940 KiB
#include <algorithm> #include <cassert> #include <cstdio> #include <iostream> #include <string> #include <vector> #include <set> #include <map> #include <numeric> #include <stack> #include <queue> #include <cmath> #include <array> using namespace std; using ll = long long; void setIO(string File_name) { cin.tie(0)->sync_with_stdio(0); if (File_name.size()) { freopen((File_name + ".in").c_str(), "r", stdin); freopen((File_name + ".out").c_str(), "w", stdout); } } void sol() { int n, m; cin >> n >> m; vector<int> a(n), b(m); for(int i = 0; i < n; i++){ cin >> a[i]; } for(int i = 0; i < m; i++){ cin >> b[i]; } map<int, vector<int>> possible_sums; for(int mask = 0; mask < (1 << m); mask++){ ll sum = 0; for(int bit = 0; bit < m; bit++){ if(mask & (1ll << bit)){ sum += b[bit]; } } possible_sums[sum].push_back(mask); } vector<vector<bool>> dp(1 << m, vector<bool>(n + 1)); for(int mask = 0; mask < (1 << m); mask++){ dp[mask][0] = 1; } for(int i = 1; i <= n; i++){ int x = a[i - 1]; vector<int> possibilities = possible_sums[x]; for(auto el : possibilities){ for(int mask = 0; mask < (1 << m); mask++){ bool been = false; for(int bit = 0; bit < m; bit++){ if((el & (1 << bit)) && (mask & (1 << bit))){ been = true; break; } } if(!been){ if(dp[mask][i - 1]){ dp[el | mask][i] = true; } } } } } for(int mask = 0; mask < (1 << m); mask++){ if(dp[mask][n]){ cout << "YES"; return; } } cout << "NO"; } int main() { setIO(""); int T = 1; //cin >> T; while (T--) sol(); return 0; }

Compilation message (stderr)

bank.cpp: In function 'void setIO(std::string)':
bank.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen((File_name + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         freopen((File_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...