제출 #1017123

#제출 시각아이디문제언어결과실행 시간메모리
1017123daviedu은행 (IZhO14_bank)C++17
71 / 100
1056 ms8792 KiB
#include <bits/stdc++.h>
using namespace std;
 
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ll long long
 
struct P{
    ll x, y;
};
 
void dbg_out() { cerr << endl; }
template <typename H, typename... T>
void dbg_out(H h, T... t) { cerr << ' ' << h; dbg_out(t...); }
#define dbg(...) { cerr << #__VA_ARGS__ << ':'; dbg_out(__VA_ARGS__); }

const int MAXN = 1<<20;
 
signed main(){
    fastio;
    int n, m;
    cin >> n >> m;
    vector<int> pay (n), notes (m);
    for (auto &a: pay) cin >> a;
    for (auto &a: notes) cin >> a;
    bool ans=false;
    vector<pair<int, int>> dp (1 << m, {-1, 0});
    for (int i=0; i<n; i++){
        for (int mask=1; mask<(1<<m); mask++){
            pair<int, int> other = {-1, 0};
            int c=-1;
            for (int j=0; j<m; j++){
                if (!(mask & (1 << j))) continue;
                if (dp[mask ^ (1 << j)] >= other){
                    other = dp[mask ^ (1 << j)];
                    c = j;
                }
            }
            assert(c != -1);
            int v = other.second + notes[c];
            if (other.first == i) dp[mask] = {i, v};
            else if (other.first == i-1){
                if (v == pay[i]) dp[mask] = {i, 0};
                else dp[mask] = {i-1, v};
            }
            if (dp[mask].first == n-1) ans = true;
        }
    }
 
    cout << (ans? "YES" : "NO") << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...