Submission #366692

# Submission time Handle Problem Language Result Execution time Memory
366692 2021-02-15T03:11:12 Z Mamnoon_Siam Cats or Dogs (JOI18_catdog) C++17
38 / 100
3000 ms 7768 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

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

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

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

void solve(int u, int dad = 0) {
  for(int v : g[u]) if(v != dad) {
    solve(v, u);
  }
  dp[u][0] = dp[u][1] = dp[u][2] = inf;
  dp[u][state[u]] = 0;
  for(int v : g[u]) if(v != dad) {
    vi me(dp[u], dp[u]+3), ch(dp[v], dp[v]+3);
    dp[u][0] = dp[u][1] = dp[u][2] = inf;
    for(int i : {0,1,2}) {
      for(int j : {0,1,2}) {
        chkmin(dp[u][i], me[i] + ch[j] + 1);
        if((i|j) != 3) {
          chkmin(dp[u][i|j], me[i] + ch[j]);
        }
      }
    }
  }
}

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(dp[1], dp[1]+3);
}

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

int neighbor(int v) {
  state[v] = 0;
  solve(1);
  return *min_element(dp[1], dp[1]+3);
}
# 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 3 ms 2668 KB Output is correct
5 Correct 2 ms 2668 KB Output is correct
6 Correct 2 ms 2668 KB Output is correct
7 Correct 2 ms 2668 KB Output is correct
8 Correct 2 ms 2668 KB Output is correct
9 Correct 2 ms 2668 KB Output is correct
10 Correct 2 ms 2668 KB Output is correct
11 Correct 2 ms 2668 KB Output is correct
12 Correct 2 ms 2668 KB Output is correct
13 Correct 2 ms 2668 KB Output is correct
14 Correct 2 ms 2668 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 3 ms 2668 KB Output is correct
5 Correct 2 ms 2668 KB Output is correct
6 Correct 2 ms 2668 KB Output is correct
7 Correct 2 ms 2668 KB Output is correct
8 Correct 2 ms 2668 KB Output is correct
9 Correct 2 ms 2668 KB Output is correct
10 Correct 2 ms 2668 KB Output is correct
11 Correct 2 ms 2668 KB Output is correct
12 Correct 2 ms 2668 KB Output is correct
13 Correct 2 ms 2668 KB Output is correct
14 Correct 2 ms 2668 KB Output is correct
15 Correct 2 ms 2668 KB Output is correct
16 Correct 2 ms 2668 KB Output is correct
17 Correct 62 ms 2796 KB Output is correct
18 Correct 75 ms 2804 KB Output is correct
19 Correct 38 ms 2668 KB Output is correct
20 Correct 4 ms 2668 KB Output is correct
21 Correct 16 ms 2668 KB Output is correct
22 Correct 19 ms 2796 KB Output is correct
23 Correct 89 ms 2924 KB Output is correct
24 Correct 73 ms 2796 KB Output is correct
25 Correct 35 ms 2668 KB Output is correct
26 Correct 19 ms 2668 KB Output is correct
27 Correct 9 ms 2668 KB Output is correct
28 Correct 18 ms 2796 KB Output is correct
29 Correct 75 ms 2796 KB Output is correct
30 Correct 12 ms 2668 KB Output is correct
31 Correct 9 ms 2668 KB Output is correct
32 Correct 19 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 3 ms 2668 KB Output is correct
5 Correct 2 ms 2668 KB Output is correct
6 Correct 2 ms 2668 KB Output is correct
7 Correct 2 ms 2668 KB Output is correct
8 Correct 2 ms 2668 KB Output is correct
9 Correct 2 ms 2668 KB Output is correct
10 Correct 2 ms 2668 KB Output is correct
11 Correct 2 ms 2668 KB Output is correct
12 Correct 2 ms 2668 KB Output is correct
13 Correct 2 ms 2668 KB Output is correct
14 Correct 2 ms 2668 KB Output is correct
15 Correct 2 ms 2668 KB Output is correct
16 Correct 2 ms 2668 KB Output is correct
17 Correct 62 ms 2796 KB Output is correct
18 Correct 75 ms 2804 KB Output is correct
19 Correct 38 ms 2668 KB Output is correct
20 Correct 4 ms 2668 KB Output is correct
21 Correct 16 ms 2668 KB Output is correct
22 Correct 19 ms 2796 KB Output is correct
23 Correct 89 ms 2924 KB Output is correct
24 Correct 73 ms 2796 KB Output is correct
25 Correct 35 ms 2668 KB Output is correct
26 Correct 19 ms 2668 KB Output is correct
27 Correct 9 ms 2668 KB Output is correct
28 Correct 18 ms 2796 KB Output is correct
29 Correct 75 ms 2796 KB Output is correct
30 Correct 12 ms 2668 KB Output is correct
31 Correct 9 ms 2668 KB Output is correct
32 Correct 19 ms 2668 KB Output is correct
33 Execution timed out 3083 ms 7768 KB Time limit exceeded
34 Halted 0 ms 0 KB -