Submission #49806

# Submission time Handle Problem Language Result Execution time Memory
49806 2018-06-03T09:02:08 Z mra2322001 Bank (IZhO14_bank) C++14
71 / 100
1000 ms 92504 KB
#include <bits/stdc++.h>
#define f0(i, n) for(int i=(0); i<n; i++)
#define f1(i, n) for(int i=(1); i<=n; i++)
#define bit(x, y) (((x) >> (y))&1)

using namespace std;
typedef long long ll;
const int N = 22;

int n, m, a[N], b[N];
int f[22][1 << 20];
vector <vector <int> > t[N];

int calc(int i, int s){
    if(f[i][s] >= 0) return f[i][s];
    if(i == n + 1){
        cout << "YES";
        exit(0);
    }
    int &ans = f[i][s];
    ans = 0;
    for(auto x:t[i]){
        bool ok = 1;
        for(auto y:x){
            if(bit(s, y)) ok = 0;
        }
        if(ok){
            int r = s;
            for(auto y:x){
                r = r + (1 << y);
            }
            ans = ans | calc(i + 1, r);
            if(ans) return ans;
        }
    }
    return ans;
}

main(){
    ios_base::sync_with_stdio(0);
 
    cin >> n >> m;
    f1(i, n) cin >> a[i];
    f1(i, m) cin >> b[i];

    memset(f, -1, sizeof(f));
    for(int i = 1; i <= (1 << m); i++){
        int val = 0;
        vector <int> save;
        f0(j, m){
            if(bit(i, j)) val += b[j + 1];
            if(bit(i, j)){
                save.push_back(j);
            }
        }
        f1(j, n){
            if(val==a[j]) t[j].push_back(save);
        }
    }
    calc(1, 0);
    cout << "NO";
}

Compilation message

bank.cpp:39:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
# Verdict Execution time Memory Grader output
1 Correct 71 ms 90616 KB Output is correct
2 Correct 71 ms 90784 KB Output is correct
3 Correct 70 ms 90824 KB Output is correct
4 Correct 78 ms 90844 KB Output is correct
5 Correct 340 ms 90872 KB Output is correct
6 Correct 72 ms 90872 KB Output is correct
7 Correct 72 ms 90872 KB Output is correct
8 Correct 340 ms 91320 KB Output is correct
9 Correct 337 ms 91320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 91320 KB Output is correct
2 Correct 73 ms 91320 KB Output is correct
3 Correct 72 ms 91320 KB Output is correct
4 Correct 73 ms 91320 KB Output is correct
5 Correct 70 ms 91320 KB Output is correct
6 Correct 71 ms 91320 KB Output is correct
7 Correct 71 ms 91320 KB Output is correct
8 Correct 71 ms 91320 KB Output is correct
9 Correct 72 ms 91320 KB Output is correct
10 Correct 72 ms 91320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 91320 KB Output is correct
2 Correct 76 ms 91320 KB Output is correct
3 Correct 75 ms 91320 KB Output is correct
4 Correct 75 ms 91320 KB Output is correct
5 Correct 75 ms 91320 KB Output is correct
6 Correct 74 ms 91320 KB Output is correct
7 Correct 74 ms 91320 KB Output is correct
8 Correct 74 ms 91320 KB Output is correct
9 Correct 66 ms 91320 KB Output is correct
10 Correct 74 ms 91320 KB Output is correct
11 Correct 75 ms 91320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 90616 KB Output is correct
2 Correct 71 ms 90784 KB Output is correct
3 Correct 70 ms 90824 KB Output is correct
4 Correct 78 ms 90844 KB Output is correct
5 Correct 340 ms 90872 KB Output is correct
6 Correct 72 ms 90872 KB Output is correct
7 Correct 72 ms 90872 KB Output is correct
8 Correct 340 ms 91320 KB Output is correct
9 Correct 337 ms 91320 KB Output is correct
10 Correct 72 ms 91320 KB Output is correct
11 Correct 73 ms 91320 KB Output is correct
12 Correct 72 ms 91320 KB Output is correct
13 Correct 73 ms 91320 KB Output is correct
14 Correct 70 ms 91320 KB Output is correct
15 Correct 71 ms 91320 KB Output is correct
16 Correct 71 ms 91320 KB Output is correct
17 Correct 71 ms 91320 KB Output is correct
18 Correct 72 ms 91320 KB Output is correct
19 Correct 72 ms 91320 KB Output is correct
20 Correct 74 ms 91320 KB Output is correct
21 Correct 76 ms 91320 KB Output is correct
22 Correct 75 ms 91320 KB Output is correct
23 Correct 75 ms 91320 KB Output is correct
24 Correct 75 ms 91320 KB Output is correct
25 Correct 74 ms 91320 KB Output is correct
26 Correct 74 ms 91320 KB Output is correct
27 Correct 74 ms 91320 KB Output is correct
28 Correct 66 ms 91320 KB Output is correct
29 Correct 74 ms 91320 KB Output is correct
30 Correct 75 ms 91320 KB Output is correct
31 Correct 340 ms 91320 KB Output is correct
32 Correct 348 ms 92504 KB Output is correct
33 Correct 345 ms 92504 KB Output is correct
34 Correct 350 ms 92504 KB Output is correct
35 Correct 347 ms 92504 KB Output is correct
36 Correct 354 ms 92504 KB Output is correct
37 Correct 341 ms 92504 KB Output is correct
38 Correct 344 ms 92504 KB Output is correct
39 Correct 348 ms 92504 KB Output is correct
40 Correct 348 ms 92504 KB Output is correct
41 Correct 358 ms 92504 KB Output is correct
42 Correct 549 ms 92504 KB Output is correct
43 Correct 344 ms 92504 KB Output is correct
44 Correct 349 ms 92504 KB Output is correct
45 Correct 346 ms 92504 KB Output is correct
46 Correct 345 ms 92504 KB Output is correct
47 Correct 354 ms 92504 KB Output is correct
48 Correct 347 ms 92504 KB Output is correct
49 Correct 344 ms 92504 KB Output is correct
50 Correct 343 ms 92504 KB Output is correct
51 Correct 341 ms 92504 KB Output is correct
52 Correct 341 ms 92504 KB Output is correct
53 Correct 347 ms 92504 KB Output is correct
54 Correct 356 ms 92504 KB Output is correct
55 Correct 353 ms 92504 KB Output is correct
56 Correct 347 ms 92504 KB Output is correct
57 Execution timed out 1096 ms 92504 KB Time limit exceeded
58 Halted 0 ms 0 KB -