# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1001483 | reginox | Bank (IZhO14_bank) | C++17 | 527 ms | 47696 KiB |
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 ld long double
#define all(v) begin(v), end(v)
#define pi pair<int, int>
#define vi vector<int>
#define task "test"
using namespace std;
const int maxn = 20;
ll n,m,dp[1<<21],a[21],b[21];
vi premask[1000005];
int main(){
if(fopen(task".inp","r")){
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> m;
for(ll i = 0; i < n; i++) cin >> a[i];
for(ll i = 0; i < m; i++) cin >> b[i];
for(ll mask = 1; mask < 1<<m; mask++){
ll sum = 0;
for(ll i = 0; i < m; i++){
if(mask>>i&1) sum += b[i];
}
premask[sum].push_back(mask);
}
memset(dp,-1,sizeof(dp));
dp[0] = 0;
for (ll i = 0; i < n; i++) {
for (ll mask = (1<<m)-1; mask >= 0; mask--) {
if (dp[mask] != -1) {
for (ll submask:premask[a[i]]) {
if (!(submask&mask)) {
dp[submask|mask] = dp[mask]+1;
if (dp[submask|mask] == n) {
cout << "YES";
return 0;
}
}
}
}
}
}
cout << "NO";
return 0;
}
Compilation message (stderr)
# | 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... |