This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define vi vector<int>
#define ve vector
#define ll long long
#define vl vector<ll>
#define vll vector<pair<ll,ll>>
#define onbit __builtin_popcount
#define ii pair<int,int>
#define vvi vector<vi>
#define vii vector<ii>
#define gii greater<ii>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 1e18
#define eps 1e-7
#define eps1 1e-2
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX_A 1e5+5
using namespace std;
const int MOD = 1e9+7;
const int nax = 2*1e5+5;
double PI=3.14159265359;
int arx[8]={1,1,0,-1,-1,-1, 0, 1};
int ary[8]={0,1,1, 1, 0,-1,-1,-1};
typedef complex<int> Point;
#define X real()
#define Y imag()
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
int n,m;
vi tab[21];
int dp[21][1<<21];
int search(int x,int y)
{
if (x==n) return 1;
if (dp[x][y]!=-1) return dp[x][y];
dp[x][y]=0;
for (int i = 0; i < tab[x].size(); ++i)
{
if ((tab[x][i]&y))continue;
int k=(tab[x][i]+y);
//cout <<k<<endl;
dp[x][y]=max(dp[x][y],search(x+1,k));
}
return dp[x][y];
}
int main(){
optimise;
/*#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif*/
//setIO("movie");
cin>>n>>m;
memset(dp,-1,sizeof dp);
set<int> people;
vi nabba(n);
vi ckecks(m);
for (int i = 0; i < n; ++i)
{
cin>>nabba[i];
people.insert(nabba[i]);
}
sort(nabba.begin(),nabba.end());
for (int i = 0; i < m; ++i)
{
cin>>ckecks[i];
}
for (int i = 1; i < (1<<m); ++i)
{
int sum=0;
for (int j = 0; j < m; ++j)
{
if (i&(1<<j)) sum+=ckecks[j];
}
//cout <<sum<<endl;
if (people.count(sum))
{
int k=lower_bound(nabba.begin(),nabba.end(),sum)-nabba.begin();
while (nabba[k]==sum)
{
tab[k].pb(i);
k++;
}
}
}
int c=search(0,0);
if (c==1) cout<< "YES"<<endl;
else cout << "NO"<<endl;
}
Compilation message (stderr)
bank.cpp: In function 'int search(int, int)':
bank.cpp:42:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for (int i = 0; i < tab[x].size(); ++i)
| ~~^~~~~~~~~~~~~~~
bank.cpp: In function 'void setIO(std::string)':
bank.cpp:31:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
31 | freopen((s + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:32:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
32 | freopen((s + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |