Submission #389640

# Submission time Handle Problem Language Result Execution time Memory
389640 2021-04-14T10:29:40 Z maximath_1 Cats or Dogs (JOI18_catdog) C++11
38 / 100
36 ms 4264 KB
#include "catdog.h"
#include <vector>
using namespace std;

const int MX = 1005;

int ada[MX], dp[MX][2];
vector<int> adj[MX];

void dfs(int nw, int bf){
	dp[nw][0] = dp[nw][1] = 0;
	for(int nx : adj[nw]) if(nx != bf){
		dfs(nx, nw);
		dp[nw][0] += min(dp[nx][0], dp[nx][1] + 1);
		dp[nw][1] += min(dp[nx][1], dp[nx][0] + 1);
	}

	if(ada[nw] != -1)
		dp[nw][1 - ada[nw]] = MX * MX;
}

void initialize(int N, vector<int> A, vector<int> B){
	for(int i = 1; i < N; i ++){
		adj[A[i - 1]].push_back(B[i - 1]);
		adj[B[i - 1]].push_back(A[i - 1]);
	}

	for(int i = 1; i <= N; i ++)
		ada[i] = -1;
}

int cat(int v){
	ada[v] = 1;
	dfs(1, 1);
	return min(dp[1][0], dp[1][1]);
}

int dog(int v){
	ada[v] = 0;
	dfs(1, 1);
	return min(dp[1][0], dp[1][1]);
}

int neighbor(int v){
	ada[v] = -1;
	dfs(1, 1);
	return min(dp[1][0], dp[1][1]);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 10 ms 364 KB Output is correct
18 Correct 13 ms 380 KB Output is correct
19 Correct 7 ms 332 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 3 ms 312 KB Output is correct
23 Correct 15 ms 380 KB Output is correct
24 Correct 12 ms 368 KB Output is correct
25 Correct 5 ms 332 KB Output is correct
26 Correct 3 ms 332 KB Output is correct
27 Correct 2 ms 312 KB Output is correct
28 Correct 3 ms 332 KB Output is correct
29 Correct 15 ms 332 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
31 Correct 2 ms 332 KB Output is correct
32 Correct 4 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 10 ms 364 KB Output is correct
18 Correct 13 ms 380 KB Output is correct
19 Correct 7 ms 332 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 3 ms 312 KB Output is correct
23 Correct 15 ms 380 KB Output is correct
24 Correct 12 ms 368 KB Output is correct
25 Correct 5 ms 332 KB Output is correct
26 Correct 3 ms 332 KB Output is correct
27 Correct 2 ms 312 KB Output is correct
28 Correct 3 ms 332 KB Output is correct
29 Correct 15 ms 332 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
31 Correct 2 ms 332 KB Output is correct
32 Correct 4 ms 316 KB Output is correct
33 Runtime error 36 ms 4264 KB Execution killed with signal 11
34 Halted 0 ms 0 KB -