Submission #91116

# Submission time Handle Problem Language Result Execution time Memory
91116 2018-12-26T09:57:26 Z Hideo Bank (IZhO14_bank) C++14
0 / 100
42 ms 528 KB
#include <bits/stdc++.h>
#define mk make_pair

using namespace std;

const int N = 25;

int dp[N][1 << 16], a[N], b[N], sum[1 << 16];
int n, m;

main(){
    cin >> n >> m;
    for (int i = 1; i <= n; i++){
        scanf ("%d", &a[i]);
    }
    for (int i = 1; i <= m; i++){
        scanf ("%d", &b[i]);
    }
    for (int mask = 0; mask < (1 << m); mask++){
        for (int i = 1; i <= m; i++){
            if (mask << (i - 1)){
                sum[mask] += b[i];
            }
        }
    }
    dp[0][0] = 1;
    for (int i = 1; i <= n; i++){
        for (int mask1 = 0; mask1 < (1 << m); mask1++){
            for (int mask2 = mask1; mask2 > 0; mask2 = mask1 & (mask2 - 1)){
                if (dp[i - 1][mask1 - mask2] == 1 && sum[mask2] == a[i]){
                    dp[i][mask1] = 1;
                    break;
                }
            }
        }
    }
    for (int mask = 0; mask < (1 << m); mask++){
        if (dp[n][mask]){
            cout << "YES";
            return 0;
        }
    }
    cout << "NO";
}

Compilation message

bank.cpp:11:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
bank.cpp: In function 'int main()':
bank.cpp:21:22: warning: '<<' in boolean context, did you mean '<' ? [-Wint-in-bool-context]
             if (mask << (i - 1)){
                 ~~~~~^~~~~~~~~~
bank.cpp:14:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf ("%d", &a[i]);
         ~~~~~~^~~~~~~~~~~~~
bank.cpp:17:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf ("%d", &b[i]);
         ~~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 508 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 42 ms 528 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -