This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//gm --- akezhon
#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define int long long
#define pb push_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define tm (tl+tr)/2
#define TL v+v, tl, tm
#define TR v+v+1, tm+1, tr
#define DA l <= tl && tr <= r
#define NE r < tl || tr < l
#define double long double
using namespace std;
const int N=2e7+7;
const int mod=1e9+7;
const int inf=1e18;
int n, m;
int a[30];
int b[30];
int dp[N];
void AlemAmenov(){
cin >> n >> m;
for(int i=1; i <= n; i++){
cin >> a[i];
a[i] += a[i-1];
}
for(int i=1; i < m; i++)cin >> b[i];
for(int mask=1; mask < (1<<m); mask++){
int s=0, x=0;
for(int i=1; i <= m; i++)if((1<<(i-1))&mask)s+=b[i];
for(int i=1; i <= n; i++)if(s == a[i])x = i;
if(x==1)dp[mask]=1;
else if(!x){
for(int i=1; i <= m; i++){
if((1<<(i-1))&mask)dp[mask] = (dp[mask - (1<<(i-1))], dp[mask]);
}
}
else {
for(int i=1; i <= m; i++){
if((1<<(i-1))&mask && dp[mask-(1<<(i-1))] == x-1)dp[mask] = x;
}
}
if(dp[mask] == n){
cout << "YES";
return;
}
}
cout << "NO";
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
// freopen("bank.in", "r", stdin);
// freopen("bank.out", "w", stdout);
int RealName=1;
// cin >> RealName;
// int C=0;
while(RealName--){
// cout << "Case " << ++C << ":\n";
AlemAmenov();
}
return 0;
}
Compilation message (stderr)
bank.cpp: In function 'void AlemAmenov()':
bank.cpp:40:56: warning: left operand of comma operator has no effect [-Wunused-value]
40 | if((1<<(i-1))&mask)dp[mask] = (dp[mask - (1<<(i-1))], dp[mask]);
| ~~~~~~~~~~~~~~~~~~~~^
# | 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... |