이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef pair<int, ll> pii;
typedef pair<ll, ll> pll;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
int main(){
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
// freopen("shuffle.in","r",stdin);
// freopen("shuffle.out","w",stdout);
int n, m; cin >> n >> m;
vector<int> arr(n+1);
for(int i=1;i<=n;i++) cin >> arr[i];
vector<int> bank(m);
for(int i=0;i<m;i++) cin >> bank[i];
vector<int> ps(n+1); ps[0]=0;
for(int i=1;i<=n;i++) ps[i]=ps[i-1]+arr[i];
ps.pb(INF);
vector<pii> dp((1<<m)); dp[0]={1, 0};
for(int i=1;i<(1<<m);i++){
dp[i]={-1, -1};
for(int j=0;(1<<j)<=i;j++){
if(!(i&(1<<j)) || dp[i-(1<<j)].fi==-1) continue;
int pos=dp[i-(1<<j)].fi, tot=dp[i-(1<<j)].se+arr[j];
if(tot>ps[pos]) continue;
else if(tot<ps[pos]) dp[i]={pos, tot};
else dp[i]={pos+1, 0};
}
}
if(dp[(1<<m)-1].fi==n+1) cout << "YES\n";
else cout << "NO\n";
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... |