This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// #pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include<bits/stdc++.h>
#define ll long long
#define int ll
using namespace std;
template<typename... T>
void see(T&... args) { ((cin >> args), ...);}
template<typename... T>
void put(T&&... args) { ((cout << args << " "), ...);}
template<typename... T>
void putl(T&&... args) { ((cout << args << " "), ...); cout<<'\n';}
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {cerr << *it << "=" << a << ", "; err(++it, args...);}
#define du long double
#define m_p make_pair
#define pb push_back
#define pii pair<int,int>
#define piii pair<pii,int>
#define vi vector<int>
#define vii vector<pii>
#define viii vector<pair<int,pii> >
#define si set<int>
#define sii multiset<pii>
#define siii set<pair<int,pii> >
#define F first
#define S second
#define pre precision
#define sz size()
#define all(x) x.begin(),x.end()
#ifndef ONLINE_JUDGE
#define OK cout << __LINE__ << "| "<< "---------------------------OK-----------------------" << endl;
#define deb(x) cout << __LINE__ << "| "<< #x << " = " << x << endl;
#else
#define OK
#define deb(x)
#endif
#define int long long
#define nl cout<<'\n'
#define OPEN freopen ("exam.in","r" , stdin), freopen ("exam.out","w",stdout)
const ll mod=1e9+7;
const ll inf=1e18;
const du PI=3.14;
const int N=1e6+9;
const int dx[]={-1,0,1,0};
const int dy[]={0,-1,0,1};
bool dp[29][N];
int a[N];
int b[N];
void Teemka_abi(){
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=0;i<m;i++){
cin>>b[i];
}
dp[0][0]=1;
for(int i=1;i<=n;i++){
for(int mask=0;mask<(1<<m);mask++){
int sum=0;
for(int j=0;j<m;j++){
if(mask&(1<<j)){
sum+=b[j];
}
}
if(sum==a[i]){
for(int msk=0;msk<(1<<m);msk++){
bool f=0;
for(int j=0;j<m;j++){
if(msk&(1<<j) and mask&(1<<j)){
f=1;
break;
}
}
if(dp[i-1][msk] and !f){
dp[i][mask|msk]=1;
}
}
}
}
}
bool f=0;
for(int i=0;i<(1<<m);i++){
if(dp[n][i]){
f=dp[n][i];
}
}
cout<<f;
}
signed main(){
// OPEN;
int tt=1;
// cin>>tt;
while(tt--){
Teemka_abi();
nl;
}
}
Compilation message (stderr)
bank.cpp:41: warning: "int" redefined
41 | #define int long long
|
bank.cpp:5: note: this is the location of the previous definition
5 | #define int ll
|
# | 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... |