Submission #72624

# Submission time Handle Problem Language Result Execution time Memory
72624 2018-08-26T12:13:02 Z ekrem Cats or Dogs (JOI18_catdog) C++
38 / 100
3000 ms 60972 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;

int a[N], dp[2][N];
vi gg[N], g[N];

int f(int node, int dur){
	int &r = dp[dur][node];
	if(r != -1)
		return r;
	r = 0;
	if(a[node] and a[node] - 1 != dur)
		return r = inf;
	for(int i = 0; i < g[node].size(); i++){
		int coc = g[node][i];
		r += min(f(coc, dur), f(coc, !dur) + 1);
	}
	// if(a[1] == 2)
	// 	cout << node << " " << dur << " -> " << r << endl;
	return r;
}

void hazirla(int node, int par){
	for(int i = 0; i < gg[node].size(); i++)
		if(gg[node][i] != par){
			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, -1);
}

int cat(int v){
	memset(dp, -1, sizeof dp);
	a[v] = 1;
	return min(f(1, 0), f(1, 1));
}

int dog(int v){
	memset(dp, -1, sizeof dp);
	a[v] = 2;
	return min(f(1, 0), f(1, 1));
}

int neighbor(int v){
	memset(dp, -1, sizeof dp);
	a[v] = 0;
	return min(f(1, 0), f(1, 1));
}


// 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 'int f(int, int)':
catdog.cpp:23: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:33:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < gg[node].size(); i++)
                 ~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 105 ms 55152 KB Output is correct
2 Correct 67 ms 55400 KB Output is correct
3 Correct 68 ms 55400 KB Output is correct
4 Correct 169 ms 55436 KB Output is correct
5 Correct 91 ms 55440 KB Output is correct
6 Correct 88 ms 55440 KB Output is correct
7 Correct 86 ms 55440 KB Output is correct
8 Correct 95 ms 55524 KB Output is correct
9 Correct 93 ms 55524 KB Output is correct
10 Correct 99 ms 55536 KB Output is correct
11 Correct 74 ms 55540 KB Output is correct
12 Correct 52 ms 55544 KB Output is correct
13 Correct 69 ms 55560 KB Output is correct
14 Correct 75 ms 55560 KB Output is correct
15 Correct 74 ms 55560 KB Output is correct
16 Correct 108 ms 55564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 105 ms 55152 KB Output is correct
2 Correct 67 ms 55400 KB Output is correct
3 Correct 68 ms 55400 KB Output is correct
4 Correct 169 ms 55436 KB Output is correct
5 Correct 91 ms 55440 KB Output is correct
6 Correct 88 ms 55440 KB Output is correct
7 Correct 86 ms 55440 KB Output is correct
8 Correct 95 ms 55524 KB Output is correct
9 Correct 93 ms 55524 KB Output is correct
10 Correct 99 ms 55536 KB Output is correct
11 Correct 74 ms 55540 KB Output is correct
12 Correct 52 ms 55544 KB Output is correct
13 Correct 69 ms 55560 KB Output is correct
14 Correct 75 ms 55560 KB Output is correct
15 Correct 74 ms 55560 KB Output is correct
16 Correct 108 ms 55564 KB Output is correct
17 Correct 514 ms 55692 KB Output is correct
18 Correct 431 ms 55692 KB Output is correct
19 Correct 312 ms 55692 KB Output is correct
20 Correct 61 ms 55760 KB Output is correct
21 Correct 352 ms 55764 KB Output is correct
22 Correct 214 ms 55764 KB Output is correct
23 Correct 503 ms 55796 KB Output is correct
24 Correct 775 ms 55824 KB Output is correct
25 Correct 419 ms 55824 KB Output is correct
26 Correct 183 ms 55864 KB Output is correct
27 Correct 239 ms 55864 KB Output is correct
28 Correct 231 ms 55876 KB Output is correct
29 Correct 729 ms 55892 KB Output is correct
30 Correct 275 ms 55892 KB Output is correct
31 Correct 107 ms 55892 KB Output is correct
32 Correct 355 ms 55972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 105 ms 55152 KB Output is correct
2 Correct 67 ms 55400 KB Output is correct
3 Correct 68 ms 55400 KB Output is correct
4 Correct 169 ms 55436 KB Output is correct
5 Correct 91 ms 55440 KB Output is correct
6 Correct 88 ms 55440 KB Output is correct
7 Correct 86 ms 55440 KB Output is correct
8 Correct 95 ms 55524 KB Output is correct
9 Correct 93 ms 55524 KB Output is correct
10 Correct 99 ms 55536 KB Output is correct
11 Correct 74 ms 55540 KB Output is correct
12 Correct 52 ms 55544 KB Output is correct
13 Correct 69 ms 55560 KB Output is correct
14 Correct 75 ms 55560 KB Output is correct
15 Correct 74 ms 55560 KB Output is correct
16 Correct 108 ms 55564 KB Output is correct
17 Correct 514 ms 55692 KB Output is correct
18 Correct 431 ms 55692 KB Output is correct
19 Correct 312 ms 55692 KB Output is correct
20 Correct 61 ms 55760 KB Output is correct
21 Correct 352 ms 55764 KB Output is correct
22 Correct 214 ms 55764 KB Output is correct
23 Correct 503 ms 55796 KB Output is correct
24 Correct 775 ms 55824 KB Output is correct
25 Correct 419 ms 55824 KB Output is correct
26 Correct 183 ms 55864 KB Output is correct
27 Correct 239 ms 55864 KB Output is correct
28 Correct 231 ms 55876 KB Output is correct
29 Correct 729 ms 55892 KB Output is correct
30 Correct 275 ms 55892 KB Output is correct
31 Correct 107 ms 55892 KB Output is correct
32 Correct 355 ms 55972 KB Output is correct
33 Execution timed out 3041 ms 60972 KB Time limit exceeded
34 Halted 0 ms 0 KB -