Submission #765600

# Submission time Handle Problem Language Result Execution time Memory
765600 2023-06-24T22:00:12 Z HD1 Bank (IZhO14_bank) C++14
0 / 100
114 ms 262144 KB
//we are all lost trying to be someone.
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
#define sz(x) ll(x.size())
#define reve(x) reverse(x.begin(),x.end())
#define ff first
#define ss second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii;
const ll MAX=1e5+10;
const ll mod=1e9+7;
const ll inf=1e18+7;
vector<ll>s;
ll A[MAX],B[MAX];
map<ll,vector<ll>> masks;
map<ll,vector<ll>> c;
ll dp[21][(1<<20)*3];
ll n, m;
void prin(ll x){
    for(ll i=m-1; i>=0; i--){
        cout<<((x>>i)&1);
    }
    cout<<endl;
    return;
}
bool DP(ll i, ll mask){
    if(dp[i][mask]!=-1)return dp[i][mask];
    dp[i][mask]=0;
    for(ll x: masks[s[i]]){
        if((mask&x)==x){
            if(i==0)dp[i][mask]=1;
            dp[i][mask]=dp[i][mask] or DP(i-1,mask^x);
        }
    }
    return dp[i][mask];
}
void solve(){
    cin>>n>>m;
    memset(dp, -1, sizeof dp);
    for(ll i=0; i<n; i++){
        ll a;
        cin>>a;
        s.push_back(a);
        c[a].push_back(i);
    }
    for(ll i=0; i<m; i++){
        cin>>B[i];
    }
    sort(s.begin(),s.end());
    for(ll mask=0; mask<(1<<m); mask++){
        ll sum=0;
        for(ll j=0; j<m; j++){
            if((mask>>j)&1){
                sum+=B[j];
            }
        }
        ll pos=lower_bound(s.begin(),s.end(),sum)-s.begin();
        if(pos<n and s[pos]==sum){
            masks[s[pos]].push_back(mask);
            for(ll it : c[s[pos]]) dp[it][mask]=1;
        }
    }
    if(DP(n-1,(1<<m)-1)){
        cout<<"YES"<<endl;
    }
    else cout<<"NO"<<endl;

}
int main(){
    fastio;
    solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 114 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 86 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 86 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 114 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -