Submission #392374

# Submission time Handle Problem Language Result Execution time Memory
392374 2021-04-20T23:39:28 Z SirCovidThe19th Bank (IZhO14_bank) C++14
0 / 100
3 ms 412 KB
#include <bits/stdc++.h>
using namespace std;

int main(){
    //n people, m banknotes
    int n, m;
    cin >> n >> m;
    int salary[n];
    int banknote[m];

    for (int i = 0; i < n; i++){
        cin >> salary[i];
        if (i != 0)
            salary[i] += salary[i-1];
    }
    for (int i = 0; i < m; i++) 
        cin >> banknote[i];
    
    int dp[1<<m];
    int sum[1<<m];
    memset(dp, 0, sizeof(dp));
    memset(sum, 0, sizeof(sum));
    for (int i = 1; i < (1<<m); i++)
        for (int j = 0; j < m; j++)
            if ((i&(1<<j)) != 0) sum[i] += banknote[j];

    bool valid = false;
    for (int i = 1; i < (1<<m); i++){
        for (int j = 0; j < m; j++){
            if ((i&(1<<j)) == 0)
                continue;
            if (sum[i^(1<<j)]+banknote[j] == salary[j])
                dp[i] = max(dp[i], dp[i^(1<<j)]+1);
            else
                dp[i] = max(dp[i], dp[i^(1<<j)]);
        }
        if (dp[i] == n)
            valid = true;
    }
    if (valid)
        cout<<"YES";
    else
        cout<<"NO";
} 
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 412 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -