제출 #593191

#제출 시각아이디문제언어결과실행 시간메모리
593191Do_you_copyBank (IZhO14_bank)C++17
100 / 100
31 ms8536 KiB
#include <bits/stdc++.h>
#define taskname "test"
#define fi first
#define se second
#define pb push_back
#define faster ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
using ll = long long;
using pii = pair <int, int>;
using pil = pair <int, ll>;
using pli = pair <ll, int>;
using pll = pair <ll, ll>;
using ull = unsigned ll;
mt19937 Rand(chrono::steady_clock::now().time_since_epoch().count());

ll min(const ll &a, const ll &b){
    return (a < b) ? a : b;
}

ll max(const ll &a, const ll &b){
    return (a > b) ? a : b;
}

//const ll Mod = 1000000009;
//const ll Mod2 = 999999999989;
//only use when required
const int maxN = 1e5 + 1;

int n, m;
pii dp[1 << 20];
int a[21], b[21];

void Init(){

    cin >> n >> m;
    for (int i = 0; i < n; ++i) cin >> a[i];
    for (int i = 0; i < m; ++i) cin >> b[i];
    for (int i = 0; i < 1 << m; ++i){
        dp[i] = {0, a[0]};
    }
    for (int i = 0; i < 1 << m; ++i){
        int mask = i;
        bool flag = 0;
        while (mask){
            int j = mask & -mask;
            if (dp[i ^ j].se != -1){
                if (dp[i ^ j].se >= b[__lg(j)]){
                    dp[i].se = dp[i ^ j].se - b[__lg(j)];
                    dp[i].fi = dp[i ^ j].fi;
                    if (!dp[i].se){
                        ++dp[i].fi;
                        if (dp[i].fi == n){
                            //bitset <5> foo(i);
                            //cerr << foo << " ";
                            cout << "YES\n"; return;
                        }
                        dp[i].se = a[dp[i].fi];
                    }
                    flag = 1;
                    break;
                }
            }
            mask ^= j;
        }
        if (!flag && i) dp[i].se = -1;
        //bitset<5> foo(i);
        //cerr << foo  << " " << dp[i].fi << " " << dp[i].se << "\n";
    }
    cout << "NO\n";
}


int main(){
    if (fopen(taskname".inp", "r")){
        freopen(taskname".inp", "r", stdin);
        //freopen(taskname".out", "w", stdout);
    }
    faster;
    ll tt = 1;
    //cin >> tt;
    while (tt--){
        Init();
    }
}

컴파일 시 표준 에러 (stderr) 메시지

bank.cpp: In function 'int main()':
bank.cpp:75:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...