이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
ifstream fin("bank.in");
ofstream fout("bank.out");
int n, m, s[1005], b[1005];
set<int>dp[(1 << 20) + 10];
///retin nr de oameni pe care i am platit si suma de bani ramasa
int main()
{
fin >> n >> m;
for(int i = 0; i < n; i++)
fin >> s[i];
for(int i = 0; i < m; i++){
fin >> b[i];
dp[(1 << i)].insert(b[i]);
}
for(int stare = 0; stare < (1 << m); stare++)
for(int j = 0; j < m; j++)
if(!(stare & (1 << j))){
for(auto i : dp[stare]){
dp[(stare | (1 << j))].insert(i + b[j]);
}
}
int ans = 0, cnt;
for(int i = 0; i < (1 << m) && !ans; i++){
cnt = 0;
for(int j = 0; j < n; j++)
if(dp[i].find(s[j]) != dp[i].end())
cnt++;
if(cnt == n)
ans = 1;
}
if(ans)
fout << "YES\n";
else
fout << "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... |