Submission #89347

# Submission time Handle Problem Language Result Execution time Memory
89347 2018-12-12T02:06:47 Z abil Bank (IZhO14_bank) C++14
100 / 100
387 ms 118508 KB
/**
   Solution by Abil
**/
# include <bits/stdc++.h>

# define fr first
# define sc second
# define pb push_back
# define mk make_pair
# define sz(s) s.size()
# define all(s) s.begin(),s.end()
# define int long long

using namespace std;

const long long N = (1e6 + 10);
const long long mod = (1e9 + 7);
const long long inf = (1e9 + 7 + 1e9);

int a[N],b[N];
int n, m, used[21][(1 << 20) + 10];
vector<int > v[N];
void f(int y,int x){
    if(y > n){
      cout << "YES";
      exit(0);
    }
    if(used[y][x]){
      return;
    }
    used[y][x] = 1;
    for(auto i : v[y]){
      if((x & i) == 0){
        f(y + 1,(x ^ i));
      }
    }
}
main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);cout.tie(0);
   cin >> n >> m;
   for(int i = 1;i <= n; i++){
      cin >> a[i];
   }
   for(int i = 1;i <= m; i++){
    cin >> b[i];
   }
   for(int mask = 0;mask < (1 << m); mask++){
     int sum = 0;
     for(int i = 0;i < m; i++){
      if(mask & (1 << i)){
        sum += b[i + 1];
      }
     }
     for(int i = 1;i <= n; i++){
      if(a[i] == sum){
        v[i].pb(mask);
      }
     }
   }
   f(1,0);
   cout << "NO";
}

Compilation message

bank.cpp:38:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
# Verdict Execution time Memory Grader output
1 Correct 19 ms 23928 KB Output is correct
2 Correct 19 ms 23932 KB Output is correct
3 Correct 19 ms 23932 KB Output is correct
4 Correct 23 ms 23932 KB Output is correct
5 Correct 90 ms 23932 KB Output is correct
6 Correct 20 ms 23992 KB Output is correct
7 Correct 19 ms 24024 KB Output is correct
8 Correct 90 ms 24176 KB Output is correct
9 Correct 94 ms 24176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 24176 KB Output is correct
2 Correct 23 ms 24176 KB Output is correct
3 Correct 23 ms 24176 KB Output is correct
4 Correct 22 ms 24176 KB Output is correct
5 Correct 22 ms 24248 KB Output is correct
6 Correct 22 ms 24248 KB Output is correct
7 Correct 22 ms 24248 KB Output is correct
8 Correct 22 ms 24248 KB Output is correct
9 Correct 23 ms 24248 KB Output is correct
10 Correct 22 ms 24248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 24248 KB Output is correct
2 Correct 23 ms 24248 KB Output is correct
3 Correct 23 ms 24248 KB Output is correct
4 Correct 21 ms 24248 KB Output is correct
5 Correct 24 ms 24248 KB Output is correct
6 Correct 21 ms 24248 KB Output is correct
7 Correct 24 ms 24248 KB Output is correct
8 Correct 24 ms 24308 KB Output is correct
9 Correct 20 ms 24308 KB Output is correct
10 Correct 23 ms 24308 KB Output is correct
11 Correct 20 ms 24308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 23928 KB Output is correct
2 Correct 19 ms 23932 KB Output is correct
3 Correct 19 ms 23932 KB Output is correct
4 Correct 23 ms 23932 KB Output is correct
5 Correct 90 ms 23932 KB Output is correct
6 Correct 20 ms 23992 KB Output is correct
7 Correct 19 ms 24024 KB Output is correct
8 Correct 90 ms 24176 KB Output is correct
9 Correct 94 ms 24176 KB Output is correct
10 Correct 22 ms 24176 KB Output is correct
11 Correct 23 ms 24176 KB Output is correct
12 Correct 23 ms 24176 KB Output is correct
13 Correct 22 ms 24176 KB Output is correct
14 Correct 22 ms 24248 KB Output is correct
15 Correct 22 ms 24248 KB Output is correct
16 Correct 22 ms 24248 KB Output is correct
17 Correct 22 ms 24248 KB Output is correct
18 Correct 23 ms 24248 KB Output is correct
19 Correct 22 ms 24248 KB Output is correct
20 Correct 23 ms 24248 KB Output is correct
21 Correct 23 ms 24248 KB Output is correct
22 Correct 23 ms 24248 KB Output is correct
23 Correct 21 ms 24248 KB Output is correct
24 Correct 24 ms 24248 KB Output is correct
25 Correct 21 ms 24248 KB Output is correct
26 Correct 24 ms 24248 KB Output is correct
27 Correct 24 ms 24308 KB Output is correct
28 Correct 20 ms 24308 KB Output is correct
29 Correct 23 ms 24308 KB Output is correct
30 Correct 20 ms 24308 KB Output is correct
31 Correct 92 ms 24308 KB Output is correct
32 Correct 93 ms 24444 KB Output is correct
33 Correct 98 ms 24444 KB Output is correct
34 Correct 98 ms 24444 KB Output is correct
35 Correct 108 ms 24444 KB Output is correct
36 Correct 107 ms 24444 KB Output is correct
37 Correct 94 ms 24444 KB Output is correct
38 Correct 93 ms 24444 KB Output is correct
39 Correct 97 ms 24444 KB Output is correct
40 Correct 97 ms 24444 KB Output is correct
41 Correct 106 ms 24444 KB Output is correct
42 Correct 129 ms 38532 KB Output is correct
43 Correct 97 ms 38532 KB Output is correct
44 Correct 106 ms 38532 KB Output is correct
45 Correct 97 ms 38532 KB Output is correct
46 Correct 100 ms 38532 KB Output is correct
47 Correct 106 ms 38532 KB Output is correct
48 Correct 95 ms 38532 KB Output is correct
49 Correct 94 ms 38532 KB Output is correct
50 Correct 111 ms 38532 KB Output is correct
51 Correct 103 ms 38532 KB Output is correct
52 Correct 102 ms 38532 KB Output is correct
53 Correct 103 ms 38532 KB Output is correct
54 Correct 112 ms 38532 KB Output is correct
55 Correct 108 ms 38532 KB Output is correct
56 Correct 110 ms 38532 KB Output is correct
57 Correct 387 ms 118508 KB Output is correct
58 Correct 110 ms 118508 KB Output is correct