제출 #676900

#제출 시각아이디문제언어결과실행 시간메모리
676900omikron123Bank (IZhO14_bank)C++14
100 / 100
789 ms4420 KiB
// https://oj.uz/problem/view/IZhO14_bank

#include <cstdio>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
using namespace std;
typedef long long ll;

// 按顺序给a[1]...a[n]发钱
// dp[bm]: bm是哪些note用了,是否状态是合法的

int n, m;
int a[25], B[25];
int dp[1<<20];
ll psum[25];

int main() {
    scanf("%d %d", &n, &m);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        psum[i+1] = psum[i] + a[i];
    }
    for (int i = 0; i < m; i++)
        scanf("%d", &B[i]);

    dp[0] = 1;
    for (int bm = 1; bm < (1<<m); bm++) {
        for (int i = 0; i < m; i++) {
            int b = 1 << i;
            if ((bm & b) && dp[bm ^ b]) {
                ll sum = 0;
                for (int j = 0; j < m; j++)
                    if ((bm ^ b) & (1 << j)) sum += B[j];
                auto it = upper_bound(psum, psum+n+1, sum);
                if (sum + B[i] <= *it) {
                    dp[bm] = 1;
                    if (sum + B[i] == psum[n]) {
                        printf("YES");
                        return 0;
                    }
                    continue;
                }
            }
        }
    }
    printf("NO");
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

bank.cpp: In function 'int main()':
bank.cpp:20:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
bank.cpp:22:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         scanf("%d", &a[i]);
      |         ~~~~~^~~~~~~~~~~~~
bank.cpp:26:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         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...