Submission #802946

# Submission time Handle Problem Language Result Execution time Memory
802946 2023-08-02T16:18:17 Z VMaksimoski008 Bank (IZhO14_bank) C++14
19 / 100
80 ms 16724 KB
#include <bits/stdc++.h>

#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define uniq(x) x.erase(unique(all(x)), x.end())
#define rall(x) x.rbegin(), x.rend()
#define each(x, v) for(auto &x : v)
#define mp make_pair

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using str = string;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;

void setIO() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

int32_t main() {
    setIO();

    int n, m;
    cin >> n >> m;

    vector<int> need(n), money(m);
    for(int &x : need) cin >> x;
    for(int &x : money) cin >> x;

    vector<ll> done(1<<m, -1);
    vector<ll> left(1<<m, -1);
    done[0] = 0, left[0] = 0;

    for(int s=1; s<(1<<m); s++) {
        for(int i=0; i<m; i++) {
            if((s & (1 << i)) && done[s^(1<<i)] >= 0) {
                int total = left[s^(1<<i)] + money[i];
                int want = need[done[s^(1<<i)]];

                if(total == want) {
                    done[s] = 1 + done[s^(1<<i)];
                    left[s] = 0;
                } else {
                    done[s] = done[s^(1<<i)];
                    left[s] = total;
                }
            }
        }

        if(done[s] == n) {
            cout << "YES\n";
            return 0;
        }
    }

    // for(int s=0; s<(1<<m); s++) {
    //     string x = bitset<6>(s).to_string();
    //     reverse(all(x));
    //     cout << x << ": ";
    //     cout << done[s] << " " << left[s] << '\n';
    // }

    cout << "NO\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 320 KB Output is correct
4 Correct 1 ms 724 KB Output is correct
5 Correct 80 ms 16636 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 7 ms 16724 KB Output is correct
9 Correct 80 ms 16724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 320 KB Output is correct
4 Correct 1 ms 724 KB Output is correct
5 Correct 80 ms 16636 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 7 ms 16724 KB Output is correct
9 Correct 80 ms 16724 KB Output is correct
10 Incorrect 1 ms 212 KB Output isn't correct
11 Halted 0 ms 0 KB -