Submission #125781

# Submission time Handle Problem Language Result Execution time Memory
125781 2019-07-06T11:09:03 Z srvlt Bank (IZhO14_bank) C++14
71 / 100
1000 ms 4748 KB
#include <bits/stdc++.h>
#define ll long long
#define db long double
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mp make_pair
#define endl "\n"
using namespace std;

int n, m, a[20], b[20], s[(1 << 20)];
bitset <(1 << 20)> dp[20];
vector <int> d[20];
char used[1001];

void solve1() {
    cin>>m;
    for (int i = 0; i < n; i++) {
        cin>>a[i];
    }
    for (int i = 0; i < m; i++) {
        cin>>b[i];
    }
    used[0] = true;
    for (int j = 0; j < m; j++) {
        for (int i = a[0]; i >= b[j]; i--) {
            if (used[i - b[j]]) {
                used[i] = true;
            }
        }
    }
    if (used[a[0]]) {
        cout<<"YES";
    }   else {
        cout<<"NO";
    }
}

void solve2() {
    cin>>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++) {
        for (int j = 0; j < m; j++) {
            if (i & (1 << j)) {
                s[i] += b[j];
            }
        }
        for (int j = 0; j < n; j++) {
            if (s[i] == a[j]) {
                d[j].pb(i);
            }
        }
    }
    for (int i = 0; i < n; i++) {
        dp[i][0] = true;
    }
    int tmp = (1 << m);
    for (int i = 0; i < n; i++) {
        for (int j = 1; j < tmp; j++) {
            for (int k = 0; k < d[i].size(); k++) {
                if ((j & d[i][k]) == d[i][k]) {
                    if (i > 0) {
                        if (dp[i - 1][j ^ d[i][k]]) {
                            dp[i][j] = true;
                            break;
                        }
                    }   else {
                        dp[i][j] = true;
                        break;
                    }
                }
            }
        }
    }
    if (dp[n - 1][tmp - 1]) {
        cout<<"YES";
    }   else {
        cout<<"NO";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    if (n == 1) {
        solve1();
    }   else {
        solve2();
    }
}

Compilation message

bank.cpp: In function 'void solve2()':
bank.cpp:66:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int k = 0; k < d[i].size(); k++) {
                             ~~^~~~~~~~~~~~~
# 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 3 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
# 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 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
# Verdict Execution time Memory Grader output
1 Correct 4 ms 504 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 4 ms 508 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 4 ms 504 KB Output is correct
8 Correct 4 ms 504 KB Output is correct
9 Correct 4 ms 376 KB Output is correct
10 Correct 4 ms 376 KB Output is correct
11 Correct 3 ms 504 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 3 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 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 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 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 4 ms 504 KB Output is correct
21 Correct 4 ms 376 KB Output is correct
22 Correct 4 ms 508 KB Output is correct
23 Correct 5 ms 504 KB Output is correct
24 Correct 5 ms 504 KB Output is correct
25 Correct 3 ms 504 KB Output is correct
26 Correct 4 ms 504 KB Output is correct
27 Correct 4 ms 504 KB Output is correct
28 Correct 4 ms 376 KB Output is correct
29 Correct 4 ms 376 KB Output is correct
30 Correct 3 ms 504 KB Output is correct
31 Execution timed out 1074 ms 4748 KB Time limit exceeded
32 Halted 0 ms 0 KB -