Submission #95424

#TimeUsernameProblemLanguageResultExecution timeMemory
95424choikiwonBank (IZhO14_bank)C++17
19 / 100
151 ms8568 KiB
#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];
            }
        }
    }
    memset(dp, -1, sizeof(dp));
    for(int i = 0; i < (1 << M); i++) {
        if(dp[i] == N - 1) {
            printf("YES");
            return 0;
        }
        for(int j = 0; j < M; j++) {
            if(i & (1 << j)) continue;

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

    printf("NO");
}

Compilation message (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...