Submission #330390

# Submission time Handle Problem Language Result Execution time Memory
330390 2020-11-25T05:00:59 Z Vince729 Bank (IZhO14_bank) C++11
0 / 100
1000 ms 1260 KB
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<complex>
using namespace std;

typedef long long ll;
typedef complex<double> pt;
#define x() real()
#define y() imag()
#define smx(a, b) a = max(a, b)
#define smn(a, b) a = min(a, b)
#define in(mp, v) mp.find(v) != mp.end()

const int MAXN = 20;
const int MOD = 1000000007;

int n, m, a[MAXN+1], b[MAXN];
bool dp[MAXN+1][1<<MAXN];
vector<int> combs[MAXN];

int sum(int x) {
    int ret = 0, i = 1;
    for (; x; i++, x>>=1) ret += b[i]*(x&1);
    return ret;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int j = 0; j < m; j++) cin >> b[j];

    dp[0][0] = true;
    bool found = false;
    for (int i = 1; i <= n; i++) {
        found = false;
        for (int k = 0; k < (1<<m); k++) {
            if (sum(k) == a[i]) combs[i].push_back(k);
            for (int msk : combs[i]) {
                dp[i][k] |= dp[i-1][k & ~msk];
            }
            found |= dp[i][k];
            //cout << k << " " << dp[i][k] << endl;
        }
        if (!found) break;
    }
    if (found) {
        cout << "YES" << endl;
    } else cout << "NO" << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 5 ms 364 KB Output is correct
5 Correct 19 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Execution timed out 1080 ms 1260 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 492 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Incorrect 3 ms 492 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 5 ms 364 KB Output is correct
5 Correct 19 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Execution timed out 1080 ms 1260 KB Time limit exceeded
9 Halted 0 ms 0 KB -