이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//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=0; mask < (1<<m); mask++){
int s=0, x=0;
for(int i=0; i < m; i++)if((1<<i)&mask)s+=b[i+1];
for(int i=1; i <= n; i++)if(s == a[i])x = i;
if(!x){
for(int i=0; i < m; i++){
if((1<<i)&mask)dp[mask] = max(dp[mask], dp[mask - (1<<i)]);
}
}
else {
for(int i=0; i < m; i++){
if((1<<i)&mask && dp[mask - (1<<i)] == 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;
}
# | 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... |