# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
869961 | 2023-11-06T12:36:11 Z | TimAni | Bank (IZhO14_bank) | C++17 | 1000 ms | 79940 KB |
#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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 35 ms | 2988 KB | Output is correct |
5 | Correct | 176 ms | 79940 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 1 ms | 604 KB | Output is correct |
8 | Execution timed out | 1068 ms | 79444 KB | Time limit exceeded |
9 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 344 KB | Output is correct |
3 | Correct | 0 ms | 604 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 348 KB | Output is correct |
6 | Correct | 1 ms | 348 KB | Output is correct |
7 | Correct | 1 ms | 344 KB | Output is correct |
8 | Correct | 1 ms | 344 KB | Output is correct |
9 | Correct | 1 ms | 348 KB | Output is correct |
10 | Correct | 1 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 1884 KB | Output is correct |
2 | Correct | 6 ms | 1884 KB | Output is correct |
3 | Correct | 6 ms | 2140 KB | Output is correct |
4 | Correct | 9 ms | 1628 KB | Output is correct |
5 | Correct | 7 ms | 1532 KB | Output is correct |
6 | Correct | 4 ms | 2140 KB | Output is correct |
7 | Correct | 5 ms | 1884 KB | Output is correct |
8 | Correct | 6 ms | 1880 KB | Output is correct |
9 | Correct | 5 ms | 1884 KB | Output is correct |
10 | Correct | 5 ms | 1884 KB | Output is correct |
11 | Correct | 2 ms | 1628 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 35 ms | 2988 KB | Output is correct |
5 | Correct | 176 ms | 79940 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 1 ms | 604 KB | Output is correct |
8 | Execution timed out | 1068 ms | 79444 KB | Time limit exceeded |
9 | Halted | 0 ms | 0 KB | - |