# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
580543 | yutabi | Bank (IZhO14_bank) | C++14 | 1092 ms | 468 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>
using namespace std;
#define pb push_back
typedef long long ll;
typedef pair <ll,ll> ii;
int n;
int m;
vector <int> s;
vector <int> x;
bool DP2[1001][1001];
int main()
{
scanf("%d %d",&n,&m);
if(n==1){
for(int i=0;i<n;i++)
{
int a;
scanf(" %d",&a);
s.pb(a);
}
for(int i=0;i<m;i++)
{
int a;
scanf(" %d",&a);
x.pb(a);
}
DP2[0][0]=1;
for(int i=0;i<m;i++)
{
for(int j=0;j<1001;j++)
{
if(x[i]+j<1001 && DP2[i][j]==1)
{
DP2[i+1][x[i]+j]=1;
}
if(DP2[i][j])
{
DP2[i+1][j]=1;
}
}
}
if(DP2[m][s[0]])
{
printf("YES");
}
else
{
printf("NO");
}}
else{
bool table[n+1][1<<m];
bool DP[n+1][1<<m];
for(int i=0;i<1<<m;i++)
{
DP[0][i]=1;
table[0][i]=0;
}
for(int j=1;j<n+1;j++)
{
for(int i=0;i<1<<m;i++)
{
DP[j][i]=0;
table[j][i]=0;
}
}
for(int i=0;i<n;i++)
{
int a;
scanf(" %d",&a);
s.pb(a);
}
for(int i=0;i<m;i++)
{
int a;
scanf(" %d",&a);
x.pb(a);
}
for(int i=0;i<1<<m;i++)
{
int a=i;
int sum=0;
for(int j=0;j<m;j++,a/=2)
{
if(a%2)
{
sum+=x[j];
}
}
for(int j=0;j<n;j++)
{
if(s[j]==sum)
{
table[j][i]=1;
}
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<1<<m;j++)
{
for(int k=0;k<1<<m;k++)
{
if(((j&k)==0) && DP[i][j] && table[i][k])
{
DP[i+1][j|k]=1;
}
}
}
}
if(DP[n][(1<<m)-1]==1)
{
printf("YES");
}
else
{
printf("NO");
}}
}
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... |