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>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define int long long
#define pii pair<int,int>
#define ret return
#define fr first
#define sc second
#define OK puts("OK");
#define NO puts("NO");
#define YES puts("YES");
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()
#define nosol puts("-1");
#define pb push_back
#define endi puts("");
#define ordered_set tree <int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const int N = 2e6+12,INF = 1e18+7;
vector <int> g[N];
int a[N],b[N],dp[N];
main(){
int n,i,j,m,mask;
cin>>n>>m;
for (i=0;i<n;++i)
cin>>a[i];
for (j=0;j<m;++j)
cin>>b[j];
for (i=0;i<n;++i){
for (mask = 0;mask < (1<<(m));++mask){
int sum = 0;
for (j=0;j<m;++j){
if (mask&(1<<j))
sum += b[j];
}
if (sum == a[i])g[i].pb(mask);
}
}
dp[0] = 1;
for (i=0;i<n;++i){
for (mask = (1<<m);mask >= 0; --mask){
if (dp[mask] == i+1){
for (auto ms: g[i]){
if (ms&mask)continue;
int x = mask|ms;
dp[x] = max(dp[x],dp[mask]+1);
if (dp[x]> n){
YES
ret 0;
}
}
}
}
}
cout <<"NO";
}
Compilation message (stderr)
bank.cpp:24:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
24 | main(){
| ^~~~
# | 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... |