Submission #375080

#TimeUsernameProblemLanguageResultExecution timeMemory
375080R3KTBank (IZhO14_bank)C++17
19 / 100
590 ms84308 KiB
#include <iostream> #include <vector> #include <map> #include <cmath> #include <algorithm> #include <deque> #include <queue> #include <stack> #include <set> #include <string> #include <string.h> #include <array> #include <unordered_map> #include <unordered_set> #include <iomanip> using namespace std; typedef long long ll; typedef long double ld; #define pb push_back const int N = 21; int n, m, a[N], b[N]; bool dp[N][(1 << N)]; unordered_map<int, vector<vector<int>>> all; // https://oj.uz/problem/view/IZhO14_bank int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for (int i=0; i<n; ++i) cin >> a[i]; for (int i=0; i<m; ++i) cin >> b[i]; for (int i=1; i<(1 << m); i++) { vector<int> cur; int sum=0; for (int j=0; j<m; j++) { if (((i >> j)&1)) { sum += b[j]; cur.pb(j); } } // cout << i << " " << sum << "\n"; all[sum].pb(cur); } for (int i=0; i<n; i++) { for (auto one : all[a[i]]) { int sum=0; vector<int> left; int p=0; for (int j=0; j<(int)one.size(); j++) { while (p < one[j]) { left.pb(p++); } p++; sum += (1 << one[j]); } if (i == 0) { dp[0][sum] = 1; } else { for (int j=0; j<(1 << left.size()); j++) { int cursum = 0; for (int k=0; k<(int)left.size(); k++) { if ((j >> k) & 1) { cursum += (1 << left[k]); } } if (!dp[i][sum + cursum]) { dp[i][sum + cursum] = dp[i-1][cursum]; } if (dp[i][sum + cursum]) break; } } } } // for (int i=0; i<n; i++) { // for (int j=0; j<(1 << m); j++) { // cout << dp[i][j] << " "; // } // cout << "\n"; // } for (int j=0; j<(1 << m); j++) { if (dp[n-1][j]) { cout << "YES"; return 0; } } cout << "NO"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...