Submission #495842

#TimeUsernameProblemLanguageResultExecution timeMemory
495842HalogenBank (IZhO14_bank)C++14
100 / 100
924 ms12496 KiB
#include <bits/stdc++.h>

using namespace std;

#define int long long

int N, M, A[25], B[25];

vector<int> can[25];

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

    for (int i = 0; i < N; i++) scanf("%lld", &A[i]);
    for (int i = 0; i < M; i++) scanf("%lld", &B[i]);    

    for (int j = 0; j < (1 << M); j++) {
        int cnt = 0;
        for (int i = 0; i < M; i++)
            if (j & (1 << i)) cnt += B[i];
        
        for (int i = 0; i < N; i++)
            if (cnt == A[i]) can[i].push_back(j);
    }

    unordered_set<int> cur, nxt; cur.insert(0);

    for (int i = 0; i < N; i++) {
        for (int j : cur) {
            for (int mask : can[i])
                if (mask & j) ;
                else nxt.insert(j | mask);
        }
        cur.clear();
        swap(cur, nxt);
    }

    if (cur.size()) printf("YES");
    else printf("NO");
}

Compilation message (stderr)

bank.cpp:11:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   11 | main() {
      | ^~~~
bank.cpp: In function 'int main()':
bank.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     scanf("%lld %lld", &N, &M);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~
bank.cpp:14:38: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     for (int i = 0; i < N; i++) scanf("%lld", &A[i]);
      |                                 ~~~~~^~~~~~~~~~~~~~~
bank.cpp:15:38: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     for (int i = 0; i < M; i++) scanf("%lld", &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...