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")
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
// author: amin_2008
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long
#define vi vector<int>
#define vs vector<string>
#define vc vector<char>
#define vl vector<ll>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define bpc __builtin_popcount
#define pii pair<int, int>
#define pll pair<ll, ll>
#define piii pair<pii, int>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvpii vector<vpii>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define ins insert
#define ts to_string
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define ld long double
#define ull unsigned long long
#define endl '\n'
#define int ll
using namespace std;
using namespace __gnu_pbds;
using namespace __cxx11;
template<class T> using ordered_set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int inf = 1e18;
const int mod = 1e9+7;
const int sz = 2e5+5;
const int N = 100005;
const int logg = 18;
const int P = 40000005;
const int M = 5e5+5;
int a[sz];
int b[sz];
void solve()
{
int n, m;
cin >> n >> m;
vi pref(n + 1);
for(int i = 1; i <= n; i++)
cin >> a[i],
pref[i] = pref[i-1] + a[i];
for(int i = 0; i < m; i++) cin >> b[i];
vector<vector<bool>> dp(n + 1, vector<bool>( 1 << m ));
for(int i = 0; i < ( 1 << m ); i++) dp[0][i] = true;
for(int j = 0; j < ( 1 << m ); j++)
{
int s = 0;
for(int i = 0; i < m; i++)
if ( ( j >> i ) & 1 )
s += b[i];
for(int i = 1; i <= n; i++)
{
if ( s == pref[i] and dp[i-1][j] )
dp[i][j] = true;
for(int k = 0; k < m; k++)
if ( ( ( j >> k ) & 1 ) and dp[i][j - ( 1 << k )] )
dp[i][j] = true;
}
}
cout << ( count(all(dp[n]), true) ? "YES" : "NO" ) << endl;
}
signed main()
{
ios;
//precompute();
int t = 1;
//cin >> t;
while(t--){
solve();
}
}
# | 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... |