# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
392464 | patrikpavic2 | Bank (IZhO14_bank) | C++17 | 115 ms | 14764 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 <cstdio>
#include <vector>
#include <cstring>
#define PB push_back
using namespace std;
const int N = 20;
const int MSK = (1 << 20);
vector < int > v[N];
int A[N], B[N], n, m, P[N];
int dp[MSK], sm[MSK];
int main(){
scanf("%d%d", &n, &m);
for(int i = 0;i < n;i++){
scanf("%d", A + i);
P[i] = A[i] + (i ? P[i - 1] : 0);
}
for(int i = 0;i < m;i++)
scanf("%d", B + i);
for(int msk = 0;msk < (1 << m);msk++){
for(int i = 0;i < m;i++)
sm[msk] += B[i] * !!(msk & (1 << i));
int gd = 0;
while(gd < n && P[gd] < sm[msk]) gd++;
v[gd].PB(msk); dp[msk] = 1;
}
for(int i = 1;i <= n;i++){
vector < int > dobri;
for(int x : v[i - 1])
if(sm[x] == P[i - 1] && dp[x])
dobri.PB(x);
memset(dp, 0, sizeof(dp));
if(i == n){
printf((int)dobri.size() ? "YES\n" : "NO\n");
return 0;
}
memset(dp, 0, sizeof(dp));
for(int x : dobri) dp[x] = 1;
for(int j = 0;j < m;j++){
for(int x : v[i]){
if(x & (1 << j))
dp[x] |= dp[x ^ (1 << j)];
}
}
}
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... |