이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
int val[1002], cnt[1002], sal[20], note[20];
vector<int> v;
int ok[21][1<<20];
vector<int> poss[20];
bool inc(int a, int b) {
for (auto i: v) {
int x = 0;
while(a>=val[i])
x++,a-=val[i];
while(b>=val[i])
x--,b-=val[i];
if(x<0) return 0;
}
return 1;
}
int main() {
int n, m;
cin >> n >> m;
for(int i = 0; i < n; i++)
cin >> sal[i];
for(int i = 0; i < m; i++)
cin >> note[i], cnt[note[i]]++;
val[0]=1;
for(int i = 1; i < 1002; i++) {
val[i]=val[i-1]*(1+cnt[i-1]);
if(cnt[i])
v.push_back(i);
}
reverse(v.begin(),v.end());
ok[0][0]=1;
for(int i = 0; i < val[1001]; i++) {
int sum = 0;
int i2 = i;
for(auto j: v) {
while(i2>=val[j])
i2-=val[j],sum+=j;
}
for(int j = 0; j < m; j++)
if(sum==sal[j])
poss[j].push_back(i);
}
for(int i = 1; i <= n; i++)
for(auto k: poss[i-1])
for(int j = 0; j < val[1001]; j++)
if(inc(j,k)&&ok[i-1][j-k]) {
ok[i][j]=1;
if(i==n) {
cout << "YES";
return 0;
}
}
cout << "NO";
}
| # | 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... |