Submission #37763

#TimeUsernameProblemLanguageResultExecution timeMemory
37763Just_Solve_The_ProblemBank (IZhO14_bank)C++11
19 / 100
480 ms1636 KiB
#include <bits/stdc++.h>

using namespace std;

const int N = (int)22;
const int NN = (1 << 20);

int a[N], b[N];
bool dp[NN];
bool used[NN];
int n, m;

void go (int mask, vector < int > vec) {
    bool fl = 1;
    if (used[mask]) return ;
    used[mask] = 1;
    for (int i = 0; i < n; i++) {
        if (vec[i] != 0) fl = 0;
    }
    if (fl) {
//        cout << mask << endl;
        puts("YES");
        exit(0);
    }
    for (int i = 0; i < n; i++) {
        if (vec[i] == 0) continue;
        for (int j = 0; j < m; j++) {
            if (vec[i] >= b[j] && !(mask & (1 << j))) {
                vec[i] -= b[j];
                go(mask | (1 << j), vec);
                vec[i] += b[j];
            }
        }
    }
}

main () {
    scanf ("%d %d", &n, &m);
    for (int i = 0; i < n; i++) {
        scanf ("%d", a + i);
    }
    sort(a, a + n);
    for (int i = 0; i < m; i++) {
        scanf ("%d", b + i);
    }
    sort(b, b + m);
    vector < int > vec(n);
    for (int i = 0; i < n; i++) {
        vec[i] = a[i];
    }
    go(0, vec);
    puts("NO");
}

Compilation message (stderr)

bank.cpp:37:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
bank.cpp: In function 'int main()':
bank.cpp:38:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf ("%d %d", &n, &m);
     ~~~~~~^~~~~~~~~~~~~~~~~
bank.cpp:40:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf ("%d", a + i);
         ~~~~~~^~~~~~~~~~~~~
bank.cpp:44:15: 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...