Submission #258837

# Submission time Handle Problem Language Result Execution time Memory
258837 2020-08-06T15:31:06 Z karma Bank (IZhO14_bank) C++14
100 / 100
103 ms 8696 KB
#include <bits/stdc++.h>
#define pb          emplace_back
#define ll          long long
#define fi          first
#define se          second
#define mp          make_pair
//#define int         int64_t

using namespace std;

const int N = 1 << 20 | 1;
const int inf = 1e9 + 1;
typedef pair<int, int> pii;

pii f[N];
int n, m, a[30], b[30];

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define Task        "test"
    if(fopen(Task".inp", "r")) {
        freopen(Task".inp", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
    cin >> n >> m; a[n] = inf;
    for(int i = 0; i < n; ++i) cin >> a[i];
    for(int i = 0; i < m; ++i) cin >> b[i];
    fill(f, f + N, pii(-1, -1));
    f[0] = {0, 0};
    for(int i = 0; i < (1 << m); ++i) {
        if(f[i].fi >= n && f[i].se == 0) return cout << "YES", 0;
        if(f[i].fi == -1) continue;
        for(int j = 0; j < m; ++j) {
            if(i >> j & 1) continue;
            if(f[i].se + b[j] > a[f[i].fi]) continue;
            if(f[i].se + b[j] == a[f[i].fi]) {
                f[i ^ (1 << j)] = {f[i].fi + 1, 0};
                continue;
            }
            f[i ^ (1 << j)] = {f[i].fi, f[i].se + b[j]};
        }
    }
    cout << "NO";
}

Compilation message

bank.cpp: In function 'int32_t main()':
bank.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(Task".inp", "r", stdin);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:24:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(Task".out", "w", stdout);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8576 KB Output is correct
2 Correct 5 ms 8576 KB Output is correct
3 Correct 5 ms 8576 KB Output is correct
4 Correct 5 ms 8576 KB Output is correct
5 Correct 6 ms 8576 KB Output is correct
6 Correct 5 ms 8576 KB Output is correct
7 Correct 5 ms 8576 KB Output is correct
8 Correct 5 ms 8576 KB Output is correct
9 Correct 78 ms 8576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8576 KB Output is correct
2 Correct 5 ms 8576 KB Output is correct
3 Correct 5 ms 8576 KB Output is correct
4 Correct 5 ms 8576 KB Output is correct
5 Correct 5 ms 8576 KB Output is correct
6 Correct 5 ms 8576 KB Output is correct
7 Correct 5 ms 8576 KB Output is correct
8 Correct 5 ms 8576 KB Output is correct
9 Correct 5 ms 8576 KB Output is correct
10 Correct 5 ms 8576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8576 KB Output is correct
2 Correct 5 ms 8576 KB Output is correct
3 Correct 5 ms 8576 KB Output is correct
4 Correct 5 ms 8576 KB Output is correct
5 Correct 5 ms 8576 KB Output is correct
6 Correct 5 ms 8576 KB Output is correct
7 Correct 5 ms 8576 KB Output is correct
8 Correct 5 ms 8576 KB Output is correct
9 Correct 5 ms 8576 KB Output is correct
10 Correct 5 ms 8576 KB Output is correct
11 Correct 6 ms 8576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8576 KB Output is correct
2 Correct 5 ms 8576 KB Output is correct
3 Correct 5 ms 8576 KB Output is correct
4 Correct 5 ms 8576 KB Output is correct
5 Correct 6 ms 8576 KB Output is correct
6 Correct 5 ms 8576 KB Output is correct
7 Correct 5 ms 8576 KB Output is correct
8 Correct 5 ms 8576 KB Output is correct
9 Correct 78 ms 8576 KB Output is correct
10 Correct 5 ms 8576 KB Output is correct
11 Correct 5 ms 8576 KB Output is correct
12 Correct 5 ms 8576 KB Output is correct
13 Correct 5 ms 8576 KB Output is correct
14 Correct 5 ms 8576 KB Output is correct
15 Correct 5 ms 8576 KB Output is correct
16 Correct 5 ms 8576 KB Output is correct
17 Correct 5 ms 8576 KB Output is correct
18 Correct 5 ms 8576 KB Output is correct
19 Correct 5 ms 8576 KB Output is correct
20 Correct 5 ms 8576 KB Output is correct
21 Correct 5 ms 8576 KB Output is correct
22 Correct 5 ms 8576 KB Output is correct
23 Correct 5 ms 8576 KB Output is correct
24 Correct 5 ms 8576 KB Output is correct
25 Correct 5 ms 8576 KB Output is correct
26 Correct 5 ms 8576 KB Output is correct
27 Correct 5 ms 8576 KB Output is correct
28 Correct 5 ms 8576 KB Output is correct
29 Correct 5 ms 8576 KB Output is correct
30 Correct 6 ms 8576 KB Output is correct
31 Correct 76 ms 8596 KB Output is correct
32 Correct 97 ms 8592 KB Output is correct
33 Correct 14 ms 8576 KB Output is correct
34 Correct 10 ms 8576 KB Output is correct
35 Correct 7 ms 8592 KB Output is correct
36 Correct 7 ms 8576 KB Output is correct
37 Correct 6 ms 8576 KB Output is correct
38 Correct 7 ms 8576 KB Output is correct
39 Correct 5 ms 8576 KB Output is correct
40 Correct 7 ms 8576 KB Output is correct
41 Correct 7 ms 8576 KB Output is correct
42 Correct 64 ms 8576 KB Output is correct
43 Correct 9 ms 8576 KB Output is correct
44 Correct 7 ms 8576 KB Output is correct
45 Correct 6 ms 8576 KB Output is correct
46 Correct 37 ms 8596 KB Output is correct
47 Correct 6 ms 8576 KB Output is correct
48 Correct 6 ms 8576 KB Output is correct
49 Correct 6 ms 8576 KB Output is correct
50 Correct 85 ms 8696 KB Output is correct
51 Correct 8 ms 8604 KB Output is correct
52 Correct 11 ms 8576 KB Output is correct
53 Correct 103 ms 8576 KB Output is correct
54 Correct 90 ms 8576 KB Output is correct
55 Correct 84 ms 8576 KB Output is correct
56 Correct 86 ms 8576 KB Output is correct
57 Correct 85 ms 8576 KB Output is correct
58 Correct 87 ms 8576 KB Output is correct