이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
using namespace std;
ll powmod(ll base,ll exponent,ll mod){
ll ans=1;
if(base<0) base+=mod;
while(exponent){
if(exponent&1)ans=(ans*base)%mod;
base=(base*base)%mod;
exponent/=2;
}
return ans;
}
ll gcd(ll a, ll b){
if(b==0) return a;
else return gcd(b,a%b);
}
const int INF = 2e9;
const ll INFLL = 4e18;
const int upperlimit = 2e3+1;
const int mod = 1e9+7;
const int N = 20;
int dp[1<<N];
int pre[N+2];
int b[N];
int main() {
int n,m;
cin >> n >> m;
for(int i = 1; i <= n; i++){
cin >> pre[i];
pre[i] += pre[i-1];
}
for(int i = 0; i < m; i++) cin >> b[i];
for(int i = 1; i < (1<<m); i++){
int sm = 0;
for(int j = 0; j < m; j++) if(i&(1<<j)) sm += b[j];
for(int j = 0; j < m; j++){
if(i&(1<<j)){
if(pre[dp[i^(1<<j)] + 1] == sm) dp[i] = max(dp[i],dp[i^(1<<j)] + 1);
else dp[i] = max(dp[i],dp[i^(1<<j)]);
}
}
}
if(dp[(1<<m) - 1] < n) cout << "NO";
else cout << "YES";
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... |