Submission #415722

# Submission time Handle Problem Language Result Execution time Memory
415722 2021-06-01T12:11:19 Z MarcoMeijer Cats or Dogs (JOI18_catdog) C++14
38 / 100
3000 ms 29816 KB
#include "catdog.h"
#include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> ii;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;

#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define RE(a,b) REP(a,0,b)
#define RE1(a,b) REP(a,1,b+1)
#define FOR(a,b) for(auto& a : b)
#define pb push_back
#define all(a) a.begin(),a.end()
#define fi first
#define se second

const int INF	= 1e9;
const int MX	= 5e5;
const int N	  = 1<<20;
const int MOD	= 1e9+7;

int n;
int a[MX];

// tree stuff
vi adj[MX], chl[MX];
int sz[MX], par[MX], dep[MX];
void dfs(int u, int p) {
  sz[u] = 1;
  par[u] = p;
  dep[u] = dep[p]+1;
  FOR(v,adj[u]) {
    if(v == p) continue;
    dfs(v,u);
    sz[u] += sz[v];
    chl[u].pb(v);
  }
}

void initialize(int N, std::vector<int> A, std::vector<int> B) {
  n = N;
  RE(i,n-1) {
    adj[A[i]].pb(B[i]);
    adj[B[i]].pb(A[i]);
  }
  dfs(1,1);
}

// dp
int dp[MX][2];
void dfsDP(int u) {
  FOR(v,chl[u]) dfsDP(v);
  
  RE(i,2) {
    dp[u][i] = 0;
    FOR(v,chl[u])
      dp[u][i] += min(dp[v][i], dp[v][!i]+1);
    if(i == a[u]-1)
      dp[u][i] = INF;
  }
}

int solve() {
  dfsDP(1);
  return min(dp[1][0], dp[1][1]);
}

int cat(int v) {
  a[v] = 1;
  return solve();
}

int dog(int v) {
  a[v] = 2;
  return solve();
}

int neighbor(int v) {
  a[v] = 0;
  return solve();
}
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23756 KB Output is correct
2 Correct 19 ms 23692 KB Output is correct
3 Correct 20 ms 23756 KB Output is correct
4 Correct 21 ms 23756 KB Output is correct
5 Correct 20 ms 23756 KB Output is correct
6 Correct 24 ms 23792 KB Output is correct
7 Correct 16 ms 23756 KB Output is correct
8 Correct 22 ms 23756 KB Output is correct
9 Correct 20 ms 23796 KB Output is correct
10 Correct 20 ms 23792 KB Output is correct
11 Correct 21 ms 23756 KB Output is correct
12 Correct 19 ms 23736 KB Output is correct
13 Correct 19 ms 23756 KB Output is correct
14 Correct 20 ms 23716 KB Output is correct
15 Correct 19 ms 23712 KB Output is correct
16 Correct 19 ms 23752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23756 KB Output is correct
2 Correct 19 ms 23692 KB Output is correct
3 Correct 20 ms 23756 KB Output is correct
4 Correct 21 ms 23756 KB Output is correct
5 Correct 20 ms 23756 KB Output is correct
6 Correct 24 ms 23792 KB Output is correct
7 Correct 16 ms 23756 KB Output is correct
8 Correct 22 ms 23756 KB Output is correct
9 Correct 20 ms 23796 KB Output is correct
10 Correct 20 ms 23792 KB Output is correct
11 Correct 21 ms 23756 KB Output is correct
12 Correct 19 ms 23736 KB Output is correct
13 Correct 19 ms 23756 KB Output is correct
14 Correct 20 ms 23716 KB Output is correct
15 Correct 19 ms 23712 KB Output is correct
16 Correct 19 ms 23752 KB Output is correct
17 Correct 27 ms 23884 KB Output is correct
18 Correct 33 ms 23800 KB Output is correct
19 Correct 22 ms 23884 KB Output is correct
20 Correct 18 ms 23756 KB Output is correct
21 Correct 20 ms 23804 KB Output is correct
22 Correct 19 ms 23756 KB Output is correct
23 Correct 29 ms 23864 KB Output is correct
24 Correct 27 ms 23884 KB Output is correct
25 Correct 23 ms 23756 KB Output is correct
26 Correct 24 ms 23840 KB Output is correct
27 Correct 24 ms 23828 KB Output is correct
28 Correct 22 ms 23920 KB Output is correct
29 Correct 30 ms 23884 KB Output is correct
30 Correct 20 ms 23756 KB Output is correct
31 Correct 18 ms 23800 KB Output is correct
32 Correct 24 ms 23852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23756 KB Output is correct
2 Correct 19 ms 23692 KB Output is correct
3 Correct 20 ms 23756 KB Output is correct
4 Correct 21 ms 23756 KB Output is correct
5 Correct 20 ms 23756 KB Output is correct
6 Correct 24 ms 23792 KB Output is correct
7 Correct 16 ms 23756 KB Output is correct
8 Correct 22 ms 23756 KB Output is correct
9 Correct 20 ms 23796 KB Output is correct
10 Correct 20 ms 23792 KB Output is correct
11 Correct 21 ms 23756 KB Output is correct
12 Correct 19 ms 23736 KB Output is correct
13 Correct 19 ms 23756 KB Output is correct
14 Correct 20 ms 23716 KB Output is correct
15 Correct 19 ms 23712 KB Output is correct
16 Correct 19 ms 23752 KB Output is correct
17 Correct 27 ms 23884 KB Output is correct
18 Correct 33 ms 23800 KB Output is correct
19 Correct 22 ms 23884 KB Output is correct
20 Correct 18 ms 23756 KB Output is correct
21 Correct 20 ms 23804 KB Output is correct
22 Correct 19 ms 23756 KB Output is correct
23 Correct 29 ms 23864 KB Output is correct
24 Correct 27 ms 23884 KB Output is correct
25 Correct 23 ms 23756 KB Output is correct
26 Correct 24 ms 23840 KB Output is correct
27 Correct 24 ms 23828 KB Output is correct
28 Correct 22 ms 23920 KB Output is correct
29 Correct 30 ms 23884 KB Output is correct
30 Correct 20 ms 23756 KB Output is correct
31 Correct 18 ms 23800 KB Output is correct
32 Correct 24 ms 23852 KB Output is correct
33 Execution timed out 3051 ms 29816 KB Time limit exceeded
34 Halted 0 ms 0 KB -