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 optimization "O2"
#pragma GCC optimization "unroll-loop"
#pragma GCC target ("avx2")
#include <bits/stdc++.h>
#define ll int
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 20 + 1;
const ll Log2 = 20;
const ll inf = 1e9 + 7;
typedef pair<ll,ll> LL;
vector<ll> v[N];
ll n,m,a[N],b[N],dd[N],dp[N][2000000];
ll cal(){
ll res = 0;
for (ll i = 1;i <= m;i++) res += dd[i]*b[i];
return res;
}
ll Get_num(){
ll res = 0;
for (ll i = 1;i <= m;i++) if (dd[i]) res += (1ll << (i - 1));
return res;
}
void backtrack(ll i,ll pos){
if (i > m){
if (cal() == a[pos]) v[pos].push_back(Get_num());
return;
}
dd[i] = 1; backtrack(i + 1,pos);
dd[i] = 0; backtrack(i + 1,pos);
}
ll f(ll pos,ll mask){
if (pos > n) return 1;
if (dp[pos][mask] != -1) return dp[pos][mask];
ll ans = 0;
for (auto i : v[pos]){
ll now = (mask & i);
if (!now) ans = max(ans,f(pos + 1,mask | i));
}
return dp[pos][mask] = ans;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
#define task "tst"
if (fopen(task".inp", "r")){
freopen(task".inp", "r", stdin);
//freopen(task".out", "w", stdout);
}
cin>>n>>m; memset(dp,-1,sizeof(dp));
for (ll i = 1;i <= n;i++) cin>>a[i];
for (ll i = 1;i <= m;i++) cin>>b[i];
for (ll i = 1;i <= n;i++) backtrack(1,i);
if (f(1,0)) cout<<"YES";
else cout<<"NO";
}
Compilation message (stderr)
bank.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
1 | #pragma GCC optimization "O2"
|
bank.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
2 | #pragma GCC optimization "unroll-loop"
|
bank.cpp: In function 'int main()':
bank.cpp:55:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
55 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |