Submission #331896

# Submission time Handle Problem Language Result Execution time Memory
331896 2020-11-30T16:15:35 Z vitkishloh228 Bank (IZhO14_bank) C++14
71 / 100
1000 ms 90732 KB
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int maxc = 20000 + 1;
int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(m);
    for (int& i : a) cin >> i;
    for (int& i : b) cin >> i;
    vector<int> pr(n + 1);
    for (int i = 0; i < n; ++i) {
        pr[i + 1] = pr[i] + a[i];
    }
    vector<int> summask((1 << m));
    for (int mask = 0; mask < (1 << m); ++mask) {
        for (int i = 0; i < m; ++i) {
            if ((mask & (1 << i))) {
                summask[mask] += b[i];
            }
        }
    }
    vector<int> needmask = { 0 };
    vector<vector<int>> dp(n, vector<int>(1 << m));
    for (int i = 0; i < n; ++i) {
        int needsum = pr[i];
        vector<int> q;
        for (int mask = 0; mask < (1 << m); ++mask) {
            if (summask[mask] != pr[i + 1]) {
                continue;
            }
            for (auto mask1 : needmask) {
                if ((mask & mask1) == mask1) {
                    dp[i][mask] = 1;
                    q.push_back(mask);
                    break;
                }
            }
        }
        needmask = q;
    }
    for (int i = 0; i < (1 << m); ++i) {
        if (dp[n - 1][i]) {
            cout << "YES";
            return 0;
        }
    }
    cout << "NO";
}

Compilation message

bank.cpp: In function 'int main()':
bank.cpp:27:13: warning: unused variable 'needsum' [-Wunused-variable]
   27 |         int needsum = pr[i];
      |             ^~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 3 ms 748 KB Output is correct
5 Correct 76 ms 12652 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 75 ms 12652 KB Output is correct
9 Correct 79 ms 12780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 876 KB Output is correct
2 Correct 2 ms 620 KB Output is correct
3 Correct 3 ms 1132 KB Output is correct
4 Correct 3 ms 1388 KB Output is correct
5 Correct 2 ms 1132 KB Output is correct
6 Correct 2 ms 748 KB Output is correct
7 Correct 2 ms 748 KB Output is correct
8 Correct 2 ms 620 KB Output is correct
9 Correct 2 ms 1004 KB Output is correct
10 Correct 2 ms 1004 KB Output is correct
11 Correct 2 ms 1388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 3 ms 748 KB Output is correct
5 Correct 76 ms 12652 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 75 ms 12652 KB Output is correct
9 Correct 79 ms 12780 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 2 ms 876 KB Output is correct
21 Correct 2 ms 620 KB Output is correct
22 Correct 3 ms 1132 KB Output is correct
23 Correct 3 ms 1388 KB Output is correct
24 Correct 2 ms 1132 KB Output is correct
25 Correct 2 ms 748 KB Output is correct
26 Correct 2 ms 748 KB Output is correct
27 Correct 2 ms 620 KB Output is correct
28 Correct 2 ms 1004 KB Output is correct
29 Correct 2 ms 1004 KB Output is correct
30 Correct 2 ms 1388 KB Output is correct
31 Correct 79 ms 16748 KB Output is correct
32 Correct 86 ms 20972 KB Output is correct
33 Correct 102 ms 37228 KB Output is correct
34 Correct 113 ms 49644 KB Output is correct
35 Correct 112 ms 53868 KB Output is correct
36 Correct 145 ms 90732 KB Output is correct
37 Correct 85 ms 16748 KB Output is correct
38 Correct 86 ms 24940 KB Output is correct
39 Execution timed out 1085 ms 41580 KB Time limit exceeded
40 Halted 0 ms 0 KB -