Submission #366693

# Submission time Handle Problem Language Result Execution time Memory
366693 2021-02-15T03:18:32 Z Mamnoon_Siam Cats or Dogs (JOI18_catdog) C++17
38 / 100
3000 ms 6440 KB
#include "catdog.h"
#include <bits/stdc++.h>
using namespace std;

/* sorry, this is the bare minimum :'( */
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
#define all(v) begin(v), end(v)
#define sz(v) (int)(v).size()
#define fi first
#define se second

using tri = array<int, 3>;

const int N = 1e5 + 5;
const int inf = 1e9 + 5;


int n;
int state[N];
tri dp[N];
vi g[N];

void chkmin(int& x, int y) {
  x = min(x, y);
}

tri merge(tri a, tri b) {
  tri ret = {inf, inf, inf};
  for(int i : {0,1,2}) for(int j : {0,1,2}) {
    chkmin(ret[i], a[i]+b[j]+1);
    if((i|j) != 3) chkmin(ret[i|j], a[i]+b[j]);
  }
  return ret;
}

void solve(int u, int dad = 0) {
  for(int v : g[u]) if(v != dad) {
    solve(v, u);
  }
  dp[u] = {inf, inf, inf};
  dp[u][state[u]] = 0;
  for(int v : g[u]) if(v != dad) {
    dp[u] = merge(dp[u], dp[v]);
  }
}

void initialize(int _n, std::vector<int> A, std::vector<int> B) {
  n = _n;
  for(int i = 0; i < sz(A); ++i) {
    g[A[i]].emplace_back(B[i]);
    g[B[i]].emplace_back(A[i]);
  }
}

int cat(int v) {
  state[v] = 1;
  solve(1);
  return *min_element(all(dp[1]));
}

int dog(int v) {
  state[v] = 2;
  solve(1);
  return *min_element(all(dp[1]));
}

int neighbor(int v) {
  state[v] = 0;
  solve(1);
  return *min_element(all(dp[1]));
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 2 ms 2540 KB Output is correct
6 Correct 2 ms 2688 KB Output is correct
7 Correct 2 ms 2668 KB Output is correct
8 Correct 2 ms 2688 KB Output is correct
9 Correct 2 ms 2668 KB Output is correct
10 Correct 2 ms 2668 KB Output is correct
11 Correct 3 ms 2668 KB Output is correct
12 Correct 3 ms 2668 KB Output is correct
13 Correct 3 ms 2668 KB Output is correct
14 Correct 3 ms 2816 KB Output is correct
15 Correct 2 ms 2668 KB Output is correct
16 Correct 2 ms 2668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 2 ms 2540 KB Output is correct
6 Correct 2 ms 2688 KB Output is correct
7 Correct 2 ms 2668 KB Output is correct
8 Correct 2 ms 2688 KB Output is correct
9 Correct 2 ms 2668 KB Output is correct
10 Correct 2 ms 2668 KB Output is correct
11 Correct 3 ms 2668 KB Output is correct
12 Correct 3 ms 2668 KB Output is correct
13 Correct 3 ms 2668 KB Output is correct
14 Correct 3 ms 2816 KB Output is correct
15 Correct 2 ms 2668 KB Output is correct
16 Correct 2 ms 2668 KB Output is correct
17 Correct 40 ms 2796 KB Output is correct
18 Correct 63 ms 2816 KB Output is correct
19 Correct 28 ms 2668 KB Output is correct
20 Correct 3 ms 2688 KB Output is correct
21 Correct 9 ms 2668 KB Output is correct
22 Correct 11 ms 2668 KB Output is correct
23 Correct 57 ms 2668 KB Output is correct
24 Correct 47 ms 2668 KB Output is correct
25 Correct 24 ms 2668 KB Output is correct
26 Correct 11 ms 2668 KB Output is correct
27 Correct 7 ms 2668 KB Output is correct
28 Correct 12 ms 2796 KB Output is correct
29 Correct 57 ms 2924 KB Output is correct
30 Correct 8 ms 2668 KB Output is correct
31 Correct 6 ms 2668 KB Output is correct
32 Correct 13 ms 2668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 2 ms 2540 KB Output is correct
6 Correct 2 ms 2688 KB Output is correct
7 Correct 2 ms 2668 KB Output is correct
8 Correct 2 ms 2688 KB Output is correct
9 Correct 2 ms 2668 KB Output is correct
10 Correct 2 ms 2668 KB Output is correct
11 Correct 3 ms 2668 KB Output is correct
12 Correct 3 ms 2668 KB Output is correct
13 Correct 3 ms 2668 KB Output is correct
14 Correct 3 ms 2816 KB Output is correct
15 Correct 2 ms 2668 KB Output is correct
16 Correct 2 ms 2668 KB Output is correct
17 Correct 40 ms 2796 KB Output is correct
18 Correct 63 ms 2816 KB Output is correct
19 Correct 28 ms 2668 KB Output is correct
20 Correct 3 ms 2688 KB Output is correct
21 Correct 9 ms 2668 KB Output is correct
22 Correct 11 ms 2668 KB Output is correct
23 Correct 57 ms 2668 KB Output is correct
24 Correct 47 ms 2668 KB Output is correct
25 Correct 24 ms 2668 KB Output is correct
26 Correct 11 ms 2668 KB Output is correct
27 Correct 7 ms 2668 KB Output is correct
28 Correct 12 ms 2796 KB Output is correct
29 Correct 57 ms 2924 KB Output is correct
30 Correct 8 ms 2668 KB Output is correct
31 Correct 6 ms 2668 KB Output is correct
32 Correct 13 ms 2668 KB Output is correct
33 Execution timed out 3063 ms 6440 KB Time limit exceeded
34 Halted 0 ms 0 KB -