Submission #672413

# Submission time Handle Problem Language Result Execution time Memory
672413 2022-12-16T03:00:44 Z moday_morning Bank (IZhO14_bank) C++17
100 / 100
88 ms 16752 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

void solve() {
    int n, m;
    cin >> n >> m;
    vector <int> a(n), vm(m), b((1 << m)), dp((1 << m), -1);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for(int j = 0; j < m; j++){
        cin >> vm[j];
    }
    dp[0] = 0;
    b[0] = 0;
    for (int s = 1; s < (1 << m); s++) {
        for (int i = 0; i < m; i++){
            if ((s & (1 << i))) {
                int pr = s - (1 << i);
                if (dp[pr] == n) {
                    dp[s] = n;
                    break;
                }
                if (dp[pr] == -1) {
                    continue;
                }
                if (b[pr] + vm[i] < a[dp[pr]]) {
                    dp[s] = dp[pr];
                    b[s] = b[pr] + vm[i];
                    break;
                }
                if (b[pr] + vm[i] == a[dp[pr]]) {
                    dp[s] = dp[pr] + 1;
                    b[s] = 0;
                    break;
                }
 
            }
        }
    }
    if (dp[(1 << m) - 1] == n) {
        cout << "YES\n";
    }
    else {
        cout << "NO\n";
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
//    cin >> t;
    while (t--) {
        solve();
    }
}

/*
3
0 0 0
9 8 5 7
 */
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 724 KB Output is correct
5 Correct 71 ms 16724 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 31 ms 16704 KB Output is correct
9 Correct 13 ms 16724 KB Output is correct
# 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 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 2 ms 572 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 2 ms 572 KB Output is correct
11 Correct 1 ms 572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 724 KB Output is correct
5 Correct 71 ms 16724 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 31 ms 16704 KB Output is correct
9 Correct 13 ms 16724 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 2 ms 596 KB Output is correct
21 Correct 2 ms 572 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 2 ms 596 KB Output is correct
28 Correct 2 ms 596 KB Output is correct
29 Correct 2 ms 572 KB Output is correct
30 Correct 1 ms 572 KB Output is correct
31 Correct 34 ms 16744 KB Output is correct
32 Correct 20 ms 16724 KB Output is correct
33 Correct 80 ms 16724 KB Output is correct
34 Correct 74 ms 16736 KB Output is correct
35 Correct 72 ms 16724 KB Output is correct
36 Correct 75 ms 16736 KB Output is correct
37 Correct 88 ms 16724 KB Output is correct
38 Correct 71 ms 16736 KB Output is correct
39 Correct 13 ms 16704 KB Output is correct
40 Correct 72 ms 16736 KB Output is correct
41 Correct 75 ms 16724 KB Output is correct
42 Correct 79 ms 16688 KB Output is correct
43 Correct 83 ms 16724 KB Output is correct
44 Correct 72 ms 16744 KB Output is correct
45 Correct 65 ms 16724 KB Output is correct
46 Correct 81 ms 16724 KB Output is correct
47 Correct 84 ms 16740 KB Output is correct
48 Correct 33 ms 16732 KB Output is correct
49 Correct 79 ms 16736 KB Output is correct
50 Correct 26 ms 16724 KB Output is correct
51 Correct 72 ms 16732 KB Output is correct
52 Correct 74 ms 16724 KB Output is correct
53 Correct 29 ms 16704 KB Output is correct
54 Correct 26 ms 16704 KB Output is correct
55 Correct 26 ms 16724 KB Output is correct
56 Correct 19 ms 16724 KB Output is correct
57 Correct 21 ms 16752 KB Output is correct
58 Correct 19 ms 16724 KB Output is correct