이 제출은 이전 버전의 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, int> 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> pes(n);
for(int i=0;i<n;i++) cin >> pes[i];
vector<int> arr(m);
for(int i=0;i<m;i++) cin >> arr[i];
pes.pb(INF);
vector<int> mx_qnt((1<<m)), sum((1<<m));
mx_qnt[0]=sum[0]=0;
for(int i=1;i<(1<<m);i++){
mx_qnt[i]=-1;
for(int j=0;(1<<j)<=i;j++){
if(!(i&(1<<j))) continue;
int qnt=mx_qnt[i-(1<<j)], val=sum[i-(1<<j)]+arr[j];
if(val==pes[qnt]) qnt++, val=0;
if(qnt>mx_qnt[i]){
mx_qnt[i]=qnt;
sum[i]=val;
}
}
}
if(mx_qnt[(1<<m)-1]==n) 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... |