# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
361578 | shahriarkhan | Bank (IZhO14_bank) | C++14 | 2 ms | 896 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 ;
int main()
{
int n , m ;
scanf("%d%d",&n,&m) ;
int a[n+1] , b[m+1] , sum[1<<m] , log[1<<m] , dp[n+1][1<<m] ;
for(int i = 0 ; i < m ; ++i) log[1<<i] = i ;
for(int i = 1 ; i <= n ; ++i) scanf("%d",&a[i]) ;
for(int i = 1 ; i <= m ; ++i) scanf("%d",&b[i]) ;
vector<int> pos[n+1] ;
for(int i = 1 ; i < (1<<m) ; ++i)
{
sum[i] = sum[i - (i & -i)] + b[log[i & -i]] ;
for(int j = 1 ; j <= n ; ++j)
{
if(a[j]==sum[i]) pos[j].push_back(i) ;
}
}
for(int i = 0 ; i <= n ; ++i)
{
for(int j = 0 ; j < (1<<m) ; ++j)
{
dp[i][j] = 0 ;
}
}
dp[0][0] = 1 ;
for(int i = 1 ; i <= n ; ++i)
{
for(int j = 1 ; j < (1<<m) ; ++j)
{
for(int k : pos[i])
{
if((j&k)!=k) continue ;
dp[i][j] = dp[i-1][j^k] ;
if(dp[i][j]) break ;
}
}
}
for(int i = 1 ; i < (1<<m) ; ++i)
{
if(dp[n][i])
{
puts("YES") ;
return 0 ;
}
}
puts("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... |