Submission #95425

# Submission time Handle Problem Language Result Execution time Memory
95425 2019-02-01T05:48:00 Z choikiwon Bank (IZhO14_bank) C++17
100 / 100
210 ms 8696 KB
#include<bits/stdc++.h>
using namespace std;

int N, M;
int A[22], B[22], sum[1 << 20], dp[1 << 20];

int main() {
    scanf("%d %d", &N, &M);

    for(int i = 0; i < N; i++) {
        scanf("%d", &A[i]);
    }
    for(int i = 0; i < M; i++) {
        scanf("%d", &B[i]);
    }
    for(int i = 1; i < N; i++) {
        A[i] += A[i - 1];
    }
    for(int i = 0; i < (1 << M); i++) {
        for(int j = 0; j < M; j++) {
            if(i & (1 << j)) {
                sum[i] += B[j];
            }
        }
    }
    for(int i = 0; i < (1 << M); i++) {
        if(dp[i] == N) {
            printf("YES");
            return 0;
        }
        for(int j = 0; j < M; j++) {
            if(i & (1 << j)) continue;

            if(sum[i + (1 << j)] == A[ dp[i] ]) {
                dp[i + (1 << j)] = max(dp[i + (1 << j)], dp[i] + 1);
            }
            else dp[i + (1 << j)] = max(dp[i + (1 << j)], dp[i]);
        }
    }

    printf("NO");
}

Compilation message

bank.cpp: In function 'int main()':
bank.cpp:8:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &N, &M);
     ~~~~~^~~~~~~~~~~~~~~~~
bank.cpp:11:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &A[i]);
         ~~~~~^~~~~~~~~~~~~
bank.cpp:14:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &B[i]);
         ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 144 ms 8696 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 66 ms 4600 KB Output is correct
9 Correct 146 ms 8484 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 504 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 3 ms 504 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 4 ms 504 KB Output is correct
4 Correct 4 ms 504 KB Output is correct
5 Correct 4 ms 504 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 4 ms 476 KB Output is correct
10 Correct 4 ms 504 KB Output is correct
11 Correct 4 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 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 144 ms 8696 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 66 ms 4600 KB Output is correct
9 Correct 146 ms 8484 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 504 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 3 ms 504 KB Output is correct
21 Correct 3 ms 504 KB Output is correct
22 Correct 4 ms 504 KB Output is correct
23 Correct 4 ms 504 KB Output is correct
24 Correct 4 ms 504 KB Output is correct
25 Correct 3 ms 504 KB Output is correct
26 Correct 3 ms 504 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
28 Correct 4 ms 476 KB Output is correct
29 Correct 4 ms 504 KB Output is correct
30 Correct 4 ms 504 KB Output is correct
31 Correct 144 ms 8460 KB Output is correct
32 Correct 147 ms 8672 KB Output is correct
33 Correct 144 ms 8568 KB Output is correct
34 Correct 145 ms 8564 KB Output is correct
35 Correct 146 ms 8612 KB Output is correct
36 Correct 146 ms 8568 KB Output is correct
37 Correct 144 ms 8628 KB Output is correct
38 Correct 144 ms 8664 KB Output is correct
39 Correct 70 ms 4444 KB Output is correct
40 Correct 145 ms 8568 KB Output is correct
41 Correct 151 ms 8568 KB Output is correct
42 Correct 144 ms 8572 KB Output is correct
43 Correct 149 ms 8568 KB Output is correct
44 Correct 146 ms 8680 KB Output is correct
45 Correct 66 ms 4600 KB Output is correct
46 Correct 143 ms 8568 KB Output is correct
47 Correct 146 ms 8540 KB Output is correct
48 Correct 70 ms 4472 KB Output is correct
49 Correct 151 ms 8568 KB Output is correct
50 Correct 144 ms 8504 KB Output is correct
51 Correct 150 ms 8576 KB Output is correct
52 Correct 152 ms 8568 KB Output is correct
53 Correct 158 ms 8520 KB Output is correct
54 Correct 210 ms 8532 KB Output is correct
55 Correct 152 ms 8568 KB Output is correct
56 Correct 142 ms 8492 KB Output is correct
57 Correct 143 ms 8560 KB Output is correct
58 Correct 147 ms 8552 KB Output is correct