# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
13508 | woqja125 | Bank (IZhO14_bank) | C++98 | 195 ms | 4800 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<stdio.h>
#include<set>
const int MAX = 20;
const int PMAX = 1<<MAX;
int a[MAX], b[MAX];
int s[MAX];
int cnt[PMAX];
int max(int a, int b){return a>b?a:b;}
int main()
{
int n, m;
int i, j;
scanf("%d%d", &n, &m);
for(i=0; i<n; i++)
{
scanf("%d", a+i);
s[i] += a[i];
s[i+1] += s[i];
}
for(i=0; i<m; i++)scanf("%d", b+i);
for(i=0; i<(1<<m); i++)
{
int x = i;
int sum = 0;
for(j=0; j<m; j++) if((x>>j)&1) sum += b[j];
int type = -1;
for(j=0; j<n; j++) if(s[j] == sum) type = j;
if(type == 0) cnt[i] = 1;
else if(type == -1)
{
for(j=0; j<m; j++) if((x>>j)&1) cnt[i] = max(cnt[i], cnt[i-(1<<j)]);
}
else
{
for(j=0; j<m; j++) if(((x>>j)&1) && cnt[i-(1<<j)] == type) cnt[i] = type+1;
}
if(cnt[i] == n)
{
printf("YES");
return 0;
}
}
printf("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... |