이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int MAXN = (1<<20)+10;
#define pb push_back
int n, m, salary[25], note[25];
bool dp[MAXN];
bool solve(int i, int mask) {
// Marca se da pra formar os valores de 1 a i
if(i>n) return 1;
if(dp[mask]) return 0;
dp[mask] = 1;
for(int l=1, r=m; l<=r; ) {
if(mask&(l-1)) l++;
if(mask&(r-1)) r--;
if(note[l]+note[r]<salary[i]) l++;
else if(note[l]+note[r]>salary[i]) r--;
else if(solve(i+1, mask+(1<<(l-1))+(1<<(r-1)))) return 1;
}
return 0;
}
int main() {
cin >> n >> m;
for(int i = 1; i <= n; i++)
cin >> salary[i];
for(int i = 1; i <= m; i++)
cin >> note[i];
sort(note+1, note+1+m);
if(solve(1,0)) cout << "YES\n";
else cout << "NO\n";
}
# | 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... |