Submission #375664

#TimeUsernameProblemLanguageResultExecution timeMemory
375664R3KTBank (IZhO14_bank)C++17
19 / 100
76 ms7532 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, MaxVal = 20001; int n, m, a[N], b[N]; bool dp[N][(1 << N)]; vector<int> all[MaxVal]; // https://oj.uz/problem/view/IZhO14_bank // TLE 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++) { int cur=0; int sum=0; for (int j=0; j<m; j++) { if (((i >> j)&1)) { sum += b[j]; cur += (1 << j); } } // cout << i << " " << sum << "\n"; all[sum].pb(cur); } bool work=false; for (int i=0; i<n; i++) { work = false; for (auto one : all[a[i]]) { int sum = one; if (i == 0) { dp[0][sum] = true; work=true; } else { int complement = ((1 << m) - 1) ^ sum; for (int j = complement; j>0; j = (j-1) & complement) { int cursum = ((1 << m) - 1) ^ j; if (!dp[i][sum + cursum]) { dp[i][sum + cursum] = dp[i-1][cursum]; } if (dp[i][sum + cursum]) work = true; } } } } // for (int i=0; i<n; i++) { // for (int j=0; j<(1 << m); j++) { // cout << dp[i][j] << " "; // } // cout << "\n"; // } // for (int j=(1 << m); j>=1; j--) { // if (dp[n-1][j]) { // cout << "YES"; // return 0; // } // } if (work) cout << "YES"; else 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...