Submission #175867

# Submission time Handle Problem Language Result Execution time Memory
175867 2020-01-07T11:38:43 Z Pankin Bank (IZhO14_bank) C++14
100 / 100
170 ms 1528 KB
#include <bits/stdc++.h>

/*
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("-O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

#define mp make_pair
#define ll long long
#define ld long double
#define pb push_back
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fs first
#define sc second
#define getfiles ifstream cin("input.txt"); ofstream cout("output.txt");
#define endl '\n'
#define con continue
#define pii pair<int, int>
#define all(x) x.begin(), x.end()

const int INF = 2000000005;
const ll BIG_INF = 2000000000000000005;
const int mod = 1000000007;
const int P = 31;
const ld PI = 3.141592653589793238462643;
const double eps = 1e-9;

using namespace std;

vector< pair<int, int> > dir = {
    {
        -1, 0
    },
    {
        0, 1
    },
    {
        1, 0
    },
    {
        0, -1
    }
};

bool valid(int x, int y, int n, int m) {
    return x >= 0 && y >= 0 && x < n && y < m;
}

mt19937 rng(1999999973);

const int N = 22;
int a[N], b[N], pref[N], n, m;
bool can[1 << (N - 1)];

signed main() {
    fast_io;

//    ifstream cin("bank.in");
//    ofstream cout("bank.out");

    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    pref[0] = a[0];
    for (int i = 1; i < n; i++)
        pref[i] = a[i] + pref[i - 1];
    pref[n] = INF;

    for (int i = 0; i < m; i++)
        cin >> b[i];

    can[0] = true;

    for (int mask = 0; mask < (1 << m); mask++) {
        if (!can[mask])
            continue;
        int cur = 0, sum = 0;
        for (int i = 0; i < m; i++) {
            if (((mask>>i)&1) == 1)
                sum += b[i];
        }

        while(pref[cur] <= sum)
            cur++;

        if (cur == n) {
            cout << "YES";
            return 0;
        }

        for (int i = 0; i < m; i++) {
            if (((mask>>i)&1) == 0 && sum + b[i] <= pref[cur])
                can[mask | (1 << i)] = true;
        }
    }

    cout << "NO";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 4 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 164 ms 1528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 424 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 4 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 4 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 164 ms 1528 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 380 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 424 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 2 ms 504 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 4 ms 376 KB Output is correct
31 Correct 135 ms 1456 KB Output is correct
32 Correct 154 ms 1412 KB Output is correct
33 Correct 15 ms 1400 KB Output is correct
34 Correct 4 ms 888 KB Output is correct
35 Correct 4 ms 1144 KB Output is correct
36 Correct 3 ms 504 KB Output is correct
37 Correct 4 ms 632 KB Output is correct
38 Correct 9 ms 376 KB Output is correct
39 Correct 2 ms 376 KB Output is correct
40 Correct 3 ms 376 KB Output is correct
41 Correct 3 ms 504 KB Output is correct
42 Correct 88 ms 1400 KB Output is correct
43 Correct 7 ms 1272 KB Output is correct
44 Correct 4 ms 376 KB Output is correct
45 Correct 3 ms 504 KB Output is correct
46 Correct 39 ms 1400 KB Output is correct
47 Correct 3 ms 504 KB Output is correct
48 Correct 2 ms 376 KB Output is correct
49 Correct 3 ms 508 KB Output is correct
50 Correct 167 ms 1316 KB Output is correct
51 Correct 6 ms 504 KB Output is correct
52 Correct 11 ms 1400 KB Output is correct
53 Correct 166 ms 1400 KB Output is correct
54 Correct 169 ms 1400 KB Output is correct
55 Correct 167 ms 1416 KB Output is correct
56 Correct 170 ms 1420 KB Output is correct
57 Correct 170 ms 1412 KB Output is correct
58 Correct 169 ms 1404 KB Output is correct