Submission #627189

#TimeUsernameProblemLanguageResultExecution timeMemory
627189madtuberBank (IZhO14_bank)C++14
100 / 100
139 ms8540 KiB
#include <bits/stdc++.h>
#define all(x) begin(x),end(x)
#define fir first
#define sec second
#define sz(x) x.size()
#define pb push_back
 
using namespace std;
using ll = long long;
using vi = vector<int>;
using pi = pair<int,int>;
using pdb = pair<double,double>;
using pll = pair<ll,ll>;
using vll = vector<ll>;
const double EPS = (1e-7);
 
void setio(string s){
    freopen((s + ".in").c_str(),"r",stdin);
    freopen((s + ".out").c_str(),"w",stdout);
}

void solve(){
    int n, m;
    cin >> n >> m;

    vi a(n);
    vi b(m);
    for(auto& i : a) cin >> i;
    for(auto& i : b) cin >> i;

    vector<pi> dp(1 << m);

    bool ok = 0;
    for(int i{}; i < (1 << m); i++){
        for(int j{}; j < m; j++){
            if (i & (1 << j)){
                if (dp[i ^ (1<<j)].sec + b[j] == a[dp[i^(1<<j)].fir]){
                    dp[i] = max(dp[i], {dp[i^(1<<j)].fir+1, 0});
                }else if (dp[i ^ (1<<j)].sec + b[j] < a[dp[i^(1<<j)].fir]){
                    dp[i] = max(dp[i], {dp[i^(1<<j)].fir, dp[i^(1<<j)].sec + b[j]});
                }
                ok |= dp[i].fir == n;
            }
        }
    }
    
    cout << (ok ? "YES" : "NO");
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    while(t--){
        solve();
    }
    return 0;
}

Compilation message (stderr)

bank.cpp: In function 'void setio(std::string)':
bank.cpp:18:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     freopen((s + ".in").c_str(),"r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:19:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     freopen((s + ".out").c_str(),"w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...