This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;
#define db long double
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define endl '\n'
#define all(x) x.begin(), x.end()
#define fastio\
ios_base::sync_with_stdio(0);\
cin.tie(0);\
cout.tie(0)\
const int inf = -1e9;
int a[25], b[25], n, m;
vii dp((1 << 20) + 5, {0, 0});
signed main(){
fastio;
cin >> n >> m;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
for(int i = 1; i <= m; i++){
cin >> b[i];
}
for(int mask = 1; mask < (1 << m); mask++){
for(int j = 0; j < m; j++){
if((1 << j) & mask){
int out = mask ^ (1 << j);
if(a[dp[out].first + 1] == dp[out].second + b[j + 1]){
if(dp[mask].first < dp[out].first + 1) dp[mask] = {dp[out].first + 1, 0};
}
else{
if(dp[mask].first <= dp[out].first) dp[mask] = {dp[out].first, dp[out].second + b[j + 1]};
}
}
}
}
int mx = 0;
for(int mask = 0; mask < (1 << m); mask++){
mx = max(dp[mask].first, mx);
}
if(mx == n) cout << "YES";
else cout << "NO";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |