답안 #963124

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
963124 2024-04-14T14:36:37 Z pcc Cats or Dogs (JOI18_catdog) C++17
38 / 100
18 ms 4316 KB
#include "catdog.h"
#include <bits/stdc++.h>
using namespace std;

const int mxn = 1010;
int x;
vector<int> tree[mxn];
int dp[mxn][3];
int N;
int arr[mxn];

void initialize(int NN, std::vector<int> A, std::vector<int> B) {
	memset(arr,0,sizeof(arr));
	N = NN;
	for(int i = 0;i<N-1;i++){
		int a= A[i],b = B[i];
		tree[a].push_back(b);
		tree[b].push_back(a);
	}
	return;
}


void dfs(int now,int par){
	memset(dp[now],0,sizeof(dp[now]));
	for(auto nxt:tree[now]){
		if(nxt == par)continue;
		dfs(nxt,now);
		if(arr[now] == 0)dp[now][0] += min({dp[nxt][0],dp[nxt][1]+1,dp[nxt][2]+1});
		if(arr[now] != 2)dp[now][1] += min({dp[nxt][0],dp[nxt][1],dp[nxt][2]+1});
		if(arr[now] != 1)dp[now][2] += min({dp[nxt][0],dp[nxt][1]+1,dp[nxt][2]});
	}
	if(arr[now]){
		for(int i = 0;i<3;i++){
			if(arr[now] != i)dp[now][i] = mxn;
		}
	}
	return;
}

int answer(){
	dfs(1,1);
	return *min_element(dp[1],dp[1]+3);
}

int cat(int v) {
	arr[v] = 1;
	return answer();
}

int dog(int v) {
	arr[v] = 2;
	return answer();
}

int neighbor(int v) {
	arr[v] = 0;
	return answer();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 456 KB Output is correct
10 Correct 1 ms 504 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 456 KB Output is correct
10 Correct 1 ms 504 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 7 ms 348 KB Output is correct
18 Correct 8 ms 532 KB Output is correct
19 Correct 4 ms 520 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 3 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 11 ms 532 KB Output is correct
24 Correct 8 ms 344 KB Output is correct
25 Correct 4 ms 348 KB Output is correct
26 Correct 2 ms 500 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 3 ms 348 KB Output is correct
29 Correct 11 ms 588 KB Output is correct
30 Correct 2 ms 348 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 3 ms 352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 456 KB Output is correct
10 Correct 1 ms 504 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 7 ms 348 KB Output is correct
18 Correct 8 ms 532 KB Output is correct
19 Correct 4 ms 520 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 3 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 11 ms 532 KB Output is correct
24 Correct 8 ms 344 KB Output is correct
25 Correct 4 ms 348 KB Output is correct
26 Correct 2 ms 500 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 3 ms 348 KB Output is correct
29 Correct 11 ms 588 KB Output is correct
30 Correct 2 ms 348 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 3 ms 352 KB Output is correct
33 Runtime error 18 ms 4316 KB Execution killed with signal 11
34 Halted 0 ms 0 KB -