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 ll long long
#define ii pair < int , int >
#define iii pair < int , ii>
#define iv pair < ii , ii >
#define fi first
#define se second
using namespace std;
const int N = 23;
const int mod = 1e9 + 7;
const int tt = 1e6;
const int base = 311;
int n, m;
int a[N], b[N], s[1 << N], presum[N], d[1 << N];
bool dp[1 << N];
main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; i++) cin >> a[i], presum[i] = presum[i - 1] + a[i];
for(int j = 0; j < m; j++) cin >> b[j];
for(int mask = 0; mask < (1 << m); mask++)
{
int sum = 0;
for(int j = 0; j < m; j++)
if((mask >> j) & 1)
sum += b[j];
s[mask] = sum;
}
int cur = 0;
dp[0] = 1;
d[0] = 0;
for(int mask = 1; mask < (1 << m); mask++){
int check = 0;
for(int j = 0; j < m; j++)
if(dp[mask ^ (1 << j)] == 1 && d[mask ^ (1 << j)] == cur)
check = 1;
if(check){
dp[mask] = 1;
d[mask] = cur;
if(s[mask] == presum[cur + 1]) cur++;
// cout << s[mask] << " " << presum[cur + 1] << endl;
}
// cout << mask << " " << dp[mask] << " " << d[mask] << endl;
}
// cout << cur << endl;
if(cur >= n) cout << "YES";
else cout << "NO";
}
Compilation message (stderr)
bank.cpp:18:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
18 | 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... |