답안 #72961

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
72961 2018-08-27T09:57:22 Z ekrem Cats or Dogs (JOI18_catdog) C++
38 / 100
3000 ms 80148 KB
#include <bits/stdc++.h>
#include "catdog.h"
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define inf 1000000007
#define N 1000005
using namespace std;

typedef vector < int > vi;
typedef pair < int , int > ii;

int a[N], par[22][N];
ii dp[N];
vi gg[N], g[N];

// void f(int node){
// 	int bir = 0, iki = 0;
// 	for(int i = 0; i < g[node].size(); i++){
// 		int coc = g[node][i];
// 		f(coc);
// 		bir += dp[coc].st;
// 		iki += dp[coc].nd;
// 	}
// 	if(a[node] == 1)
// 		iki = inf;
// 	if(a[node] == 2)
// 		bir = inf;
// 	// cout << node << " -> " << bir << " " << iki << endl;
// 	//bir = f(node, 0)
// 	//iki = f(node, 1)
// 	dp[node].st = min(bir, iki + 1);
// 	dp[node].nd = min(bir + 1, iki);
// }

void f(int node){
	if(!node)
		return;
	int bir = 0, iki = 0;
	for(int i = 0; i < g[node].size(); i++){
		int coc = g[node][i];
		bir += dp[coc].st;
		iki += dp[coc].nd;
	}
	if(a[node] == 1)
		iki = inf;
	if(a[node] == 2)
		bir = inf;
	// cout << node << " -> " << bir << " " << iki << endl;
	dp[node].st = min(bir, iki + 1);
	dp[node].nd = min(bir + 1, iki);
	f(par[0][node]);
}

void hazirla(int node, int pr){
	par[0][node] = pr;
	for(int i = 0; i < gg[node].size(); i++)
		if(gg[node][i] != pr){
			g[node].pb(gg[node][i]);
			hazirla(gg[node][i], node);
		}
}

void initialize(int n, vi a, vi b){
	for(int i = 0; i < n - 1; i++){
		gg[a[i]].pb(b[i]);
		gg[b[i]].pb(a[i]);
	}
	hazirla(1, 0);
}

int cat(int v){//cout << "AMK:\n";
	a[v] = 1;
	f(v);
	return min(dp[1].st, dp[1].nd);
}

int dog(int v){//cout << "AMK:\n";
	a[v] = 2;
	f(v);
	return min(dp[1].st, dp[1].nd);
}

int neighbor(int v){//cout << "AMK:\n";
	a[v] = 0;
	f(v);
	return min(dp[1].st, dp[1].nd);
}


// int main(){
// 	freopen("in.txt", "r", stdin);
// 	freopen("out.txt", "w", stdout);
// 	int n, q;
// 	scanf("%d",&n);
// 	vi a(n - 1), b(n - 1);
// 	for(int i = 0; i < n - 1; i++)
// 		scanf("%d %d",&a[i] ,&b[i]);
// 	scanf("%d",&q);
// 	vi t(q), v(q);
// 	for(int i = 0; i < q; i++)
// 		scanf("%d %d",&t[i] ,&v[i]);

// 	initialize(n, a, b);
// 	vi ans(q);
// 	for(int i = 0; i < q; i++){
// 		if(t[i] == 1)
// 			ans[i] = cat(v[i]);
// 		else if(t[i] == 2)
// 			ans[i] = dog(v[i]);
// 		else
// 			ans[i] = neighbor(v[i]);
// 	}
// 	for(int i = 0; i < q; i++)
// 		printf("%d\n",ans[i]);
// 	return 0;
// }

Compilation message

catdog.cpp: In function 'void f(int)':
catdog.cpp:41:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < g[node].size(); i++){
                 ~~^~~~~~~~~~~~~~~~
catdog.cpp: In function 'void hazirla(int, int)':
catdog.cpp:58:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < gg[node].size(); i++)
                 ~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 47352 KB Output is correct
2 Correct 55 ms 47436 KB Output is correct
3 Correct 45 ms 47436 KB Output is correct
4 Correct 45 ms 47440 KB Output is correct
5 Correct 43 ms 47616 KB Output is correct
6 Correct 41 ms 47616 KB Output is correct
7 Correct 41 ms 47616 KB Output is correct
8 Correct 44 ms 47616 KB Output is correct
9 Correct 42 ms 47616 KB Output is correct
10 Correct 43 ms 47616 KB Output is correct
11 Correct 45 ms 47616 KB Output is correct
12 Correct 43 ms 47616 KB Output is correct
13 Correct 41 ms 47616 KB Output is correct
14 Correct 57 ms 47616 KB Output is correct
15 Correct 42 ms 47700 KB Output is correct
16 Correct 45 ms 47700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 47352 KB Output is correct
2 Correct 55 ms 47436 KB Output is correct
3 Correct 45 ms 47436 KB Output is correct
4 Correct 45 ms 47440 KB Output is correct
5 Correct 43 ms 47616 KB Output is correct
6 Correct 41 ms 47616 KB Output is correct
7 Correct 41 ms 47616 KB Output is correct
8 Correct 44 ms 47616 KB Output is correct
9 Correct 42 ms 47616 KB Output is correct
10 Correct 43 ms 47616 KB Output is correct
11 Correct 45 ms 47616 KB Output is correct
12 Correct 43 ms 47616 KB Output is correct
13 Correct 41 ms 47616 KB Output is correct
14 Correct 57 ms 47616 KB Output is correct
15 Correct 42 ms 47700 KB Output is correct
16 Correct 45 ms 47700 KB Output is correct
17 Correct 47 ms 47700 KB Output is correct
18 Correct 43 ms 47700 KB Output is correct
19 Correct 42 ms 47724 KB Output is correct
20 Correct 41 ms 47724 KB Output is correct
21 Correct 48 ms 47724 KB Output is correct
22 Correct 43 ms 47724 KB Output is correct
23 Correct 48 ms 47724 KB Output is correct
24 Correct 47 ms 47724 KB Output is correct
25 Correct 48 ms 47724 KB Output is correct
26 Correct 43 ms 47724 KB Output is correct
27 Correct 46 ms 47772 KB Output is correct
28 Correct 49 ms 47772 KB Output is correct
29 Correct 45 ms 47772 KB Output is correct
30 Correct 43 ms 47772 KB Output is correct
31 Correct 42 ms 47772 KB Output is correct
32 Correct 48 ms 47772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 47352 KB Output is correct
2 Correct 55 ms 47436 KB Output is correct
3 Correct 45 ms 47436 KB Output is correct
4 Correct 45 ms 47440 KB Output is correct
5 Correct 43 ms 47616 KB Output is correct
6 Correct 41 ms 47616 KB Output is correct
7 Correct 41 ms 47616 KB Output is correct
8 Correct 44 ms 47616 KB Output is correct
9 Correct 42 ms 47616 KB Output is correct
10 Correct 43 ms 47616 KB Output is correct
11 Correct 45 ms 47616 KB Output is correct
12 Correct 43 ms 47616 KB Output is correct
13 Correct 41 ms 47616 KB Output is correct
14 Correct 57 ms 47616 KB Output is correct
15 Correct 42 ms 47700 KB Output is correct
16 Correct 45 ms 47700 KB Output is correct
17 Correct 47 ms 47700 KB Output is correct
18 Correct 43 ms 47700 KB Output is correct
19 Correct 42 ms 47724 KB Output is correct
20 Correct 41 ms 47724 KB Output is correct
21 Correct 48 ms 47724 KB Output is correct
22 Correct 43 ms 47724 KB Output is correct
23 Correct 48 ms 47724 KB Output is correct
24 Correct 47 ms 47724 KB Output is correct
25 Correct 48 ms 47724 KB Output is correct
26 Correct 43 ms 47724 KB Output is correct
27 Correct 46 ms 47772 KB Output is correct
28 Correct 49 ms 47772 KB Output is correct
29 Correct 45 ms 47772 KB Output is correct
30 Correct 43 ms 47772 KB Output is correct
31 Correct 42 ms 47772 KB Output is correct
32 Correct 48 ms 47772 KB Output is correct
33 Correct 284 ms 52588 KB Output is correct
34 Correct 170 ms 53644 KB Output is correct
35 Correct 344 ms 53644 KB Output is correct
36 Correct 526 ms 59596 KB Output is correct
37 Correct 70 ms 59596 KB Output is correct
38 Correct 616 ms 62780 KB Output is correct
39 Correct 563 ms 64704 KB Output is correct
40 Correct 732 ms 66688 KB Output is correct
41 Correct 660 ms 68772 KB Output is correct
42 Correct 826 ms 70428 KB Output is correct
43 Correct 617 ms 72504 KB Output is correct
44 Correct 675 ms 74376 KB Output is correct
45 Correct 869 ms 76236 KB Output is correct
46 Correct 651 ms 78300 KB Output is correct
47 Correct 566 ms 80148 KB Output is correct
48 Execution timed out 3057 ms 80148 KB Time limit exceeded
49 Halted 0 ms 0 KB -