Submission #677716

# Submission time Handle Problem Language Result Execution time Memory
677716 2023-01-04T08:26:51 Z ismayil Bank (IZhO14_bank) C++17
100 / 100
535 ms 131128 KB
#include <bits/stdc++.h>
#define ll long long
using namespace std;
vector<vector<int>> dp, cost;
vector<int> a, b;
int n, m;
int solve(int mask, int i){
  if(i == n) return 1;
  if(dp[mask][i] != -1) return dp[mask][i];
  for(auto s : cost[a[i]]){
    if((s & mask) == s){
      if(solve(mask ^ s, i + 1)){
        return dp[mask][i] = 1;
      }
    }
  }
  return dp[mask][i] = 0;
}
int main(){
  cin>>n>>m;
  a = vector<int>(n);
  b = vector<int>(m);
  dp = vector<vector<int>>((1<<m), vector<int>(n, -1));
  for(auto& i : a) cin>>i;
  for(auto& i : b) cin>>i;
  cost.resize(30005);
  for (int mask = 0; mask < (1<<m); mask++)
  {
    int total = 0;
    for (int i = 0; i < m; i++)
    {
      if(!(mask & (1<<i))) continue;
      total += b[i];
    }
    cost[total].push_back(mask);
  }
  cout<<(solve((1<<m) - 1, 0) ? "YES" : "NO");
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 4 ms 3028 KB Output is correct
5 Correct 113 ms 64888 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 1108 KB Output is correct
8 Correct 121 ms 64044 KB Output is correct
9 Correct 112 ms 64444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 1 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2260 KB Output is correct
2 Correct 3 ms 2048 KB Output is correct
3 Correct 4 ms 2260 KB Output is correct
4 Correct 3 ms 2516 KB Output is correct
5 Correct 3 ms 2260 KB Output is correct
6 Correct 3 ms 2004 KB Output is correct
7 Correct 3 ms 2004 KB Output is correct
8 Correct 3 ms 2004 KB Output is correct
9 Correct 3 ms 2260 KB Output is correct
10 Correct 4 ms 2260 KB Output is correct
11 Correct 2 ms 2388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 4 ms 3028 KB Output is correct
5 Correct 113 ms 64888 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 1108 KB Output is correct
8 Correct 121 ms 64044 KB Output is correct
9 Correct 112 ms 64444 KB Output is correct
10 Correct 1 ms 980 KB Output is correct
11 Correct 1 ms 980 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 1 ms 980 KB Output is correct
14 Correct 1 ms 980 KB Output is correct
15 Correct 1 ms 980 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 1 ms 980 KB Output is correct
20 Correct 4 ms 2260 KB Output is correct
21 Correct 3 ms 2048 KB Output is correct
22 Correct 4 ms 2260 KB Output is correct
23 Correct 3 ms 2516 KB Output is correct
24 Correct 3 ms 2260 KB Output is correct
25 Correct 3 ms 2004 KB Output is correct
26 Correct 3 ms 2004 KB Output is correct
27 Correct 3 ms 2004 KB Output is correct
28 Correct 3 ms 2260 KB Output is correct
29 Correct 4 ms 2260 KB Output is correct
30 Correct 2 ms 2388 KB Output is correct
31 Correct 119 ms 64884 KB Output is correct
32 Correct 114 ms 64212 KB Output is correct
33 Correct 134 ms 81060 KB Output is correct
34 Correct 143 ms 81432 KB Output is correct
35 Correct 133 ms 98712 KB Output is correct
36 Correct 149 ms 131128 KB Output is correct
37 Correct 131 ms 65884 KB Output is correct
38 Correct 125 ms 65400 KB Output is correct
39 Correct 118 ms 79768 KB Output is correct
40 Correct 118 ms 81708 KB Output is correct
41 Correct 147 ms 130672 KB Output is correct
42 Correct 121 ms 64004 KB Output is correct
43 Correct 139 ms 82124 KB Output is correct
44 Correct 142 ms 114984 KB Output is correct
45 Correct 116 ms 64384 KB Output is correct
46 Correct 120 ms 65684 KB Output is correct
47 Correct 154 ms 114496 KB Output is correct
48 Correct 111 ms 64220 KB Output is correct
49 Correct 114 ms 64332 KB Output is correct
50 Correct 148 ms 128952 KB Output is correct
51 Correct 125 ms 80680 KB Output is correct
52 Correct 128 ms 79596 KB Output is correct
53 Correct 120 ms 79704 KB Output is correct
54 Correct 143 ms 128924 KB Output is correct
55 Correct 150 ms 128948 KB Output is correct
56 Correct 142 ms 129700 KB Output is correct
57 Correct 535 ms 129568 KB Output is correct
58 Correct 162 ms 129580 KB Output is correct