제출 #593454

#제출 시각아이디문제언어결과실행 시간메모리
593454tht2005Bank (IZhO14_bank)C++17
100 / 100
85 ms5544 KiB
#include <bits/stdc++.h>

using namespace std;

#define N 20
int a[N + 1], b[N], s[1 << N];
bool f[1 << N];

int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    a[0] = 0;
    for(int i = 1; i <= n; ++i) {
        scanf("%d", a + i);
        a[i] += a[i - 1];
    }
    s[0] = 0;
    for(int i = 0; i < m; ++i) {
        scanf("%d", b + i);
        s[1 << i] = b[i];
    }
    f[0] = 1;
    for(int t = 0, w; t < 1 << m; ++t) {
        w = t & (t - 1);
        if(w) {
            s[t] = s[w] + s[t ^ w];
        }
        if(!f[t]) {
            continue;
        }
        int x = upper_bound(a, a + 1 + n, s[t]) - a - 1, cur = s[t];
        for(int i = 0; i < m; ++i) {
            if((t >> i & 1) || cur + b[i] > a[x + 1]) {
                continue;
            }
            if(x + 1 == n && cur + b[i] == a[x + 1]) {
                puts("YES");
                return 0;
            }
            f[t | (1 << i)] = 1;
        }
    }
    puts("NO");
    return 0;
}

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

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