Submission #95425

#TimeUsernameProblemLanguageResultExecution timeMemory
95425choikiwonBank (IZhO14_bank)C++17
100 / 100
210 ms8696 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]; } } } 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 (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...