Submission #476219

# Submission time Handle Problem Language Result Execution time Memory
476219 2021-09-25T12:03:51 Z kkk Bank (IZhO14_bank) C++14
0 / 100
121 ms 262148 KB
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
long long a[100], b[100], dp[(1<<21)][21], n, m;

bool rec(long long pos,long long mask,long long num)
{
    if(pos==n)return 1;

    if(dp[mask][pos]!=-1)return dp[mask][pos];

    bool rez=0;

    for(int i=0;i<m;i++)
    {
        if((mask&(1<<i))==0)
        {
            if(b[i]<num)
            {
               rez=max(rez, rec(pos,(mask|(1<<i)),num-b[i]));
            }
           if(b[i]==num)
           {
               rez=max(rez, rec(pos+1,(mask|(1<<i)),a[pos+1]));
           }
        }
    }
    return dp[mask][pos]=rez;

}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    long long i,j;

    memset(dp,-1,sizeof(dp));

    cin>>n>>m;

    for(i=0;i<n;i++)cin>>a[i];
    for(i=0;i<m;i++)cin>>b[i];

    if(rec(0,0,a[0]))cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

}

Compilation message

bank.cpp: In function 'bool rec(long long int, long long int, long long int)':
bank.cpp:28:25: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   28 |     return dp[mask][pos]=rez;
      |            ~~~~~~~~~~~~~^~~~
bank.cpp: In function 'int main()':
bank.cpp:38:17: warning: unused variable 'j' [-Wunused-variable]
   38 |     long long i,j;
      |                 ^
# Verdict Execution time Memory Grader output
1 Runtime error 121 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 118 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 106 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 121 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -