답안 #123944

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
123944 2019-07-02T09:57:10 Z eriksuenderhauf Cats or Dogs (JOI18_catdog) C++11
38 / 100
3000 ms 7724 KB
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include "catdog.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%I64d", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%I64d\n", (n))
#define pii pair<int, int>
#define pil pair<int, long long>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vil vector<pil>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e5 + 5;
const double eps = 1e-9;
vi adj[MAXN];
int cur[MAXN], dp[MAXN][2], val[MAXN];

void initialize(int N, vi A, vi B) {
	for (int i = 0; i+1 < N; i++) {
		A[i]--, B[i]--;
		adj[A[i]].pb(B[i]);
		adj[B[i]].pb(A[i]);
	}
}

void dfs(int u, int p) {
	if (cur[u] == 1)
		dp[u][1] = INF;
	else if (cur[u] == 2)
		dp[u][0] = INF;
	int a = 0, b = 0;
	for (int v: adj[u]) {
		if (v == p)
			continue;
		dfs(v, u);
		if (cur[u] == 1)
			dp[u][0] += min(dp[v][0], dp[v][1] + 1);
		else if (cur[u] == 2)
			dp[u][1] += min(dp[v][1], dp[v][0] + 1);
		else {
			a += min(dp[v][0], dp[v][1] + 1);
			b += min(dp[v][1], dp[v][0] + 1);
		}
	}
	if (cur[u] == 0)
		dp[u][0] = a, dp[u][1] = b;
}

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

int dog(int v) {
	cur[v-1] = 2;
	mem(dp, 0);
	dfs(0, -1);
	return min(dp[0][0], dp[0][1]);
}

int neighbor(int v) {
	cur[v-1] = 0;
	mem(dp, 0);
	dfs(0, -1);
	return min(dp[0][0], dp[0][1]);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 3448 KB Output is correct
2 Correct 6 ms 3448 KB Output is correct
3 Correct 6 ms 3448 KB Output is correct
4 Correct 10 ms 3448 KB Output is correct
5 Correct 8 ms 3448 KB Output is correct
6 Correct 9 ms 3448 KB Output is correct
7 Correct 9 ms 3448 KB Output is correct
8 Correct 8 ms 3476 KB Output is correct
9 Correct 10 ms 3448 KB Output is correct
10 Correct 9 ms 3448 KB Output is correct
11 Correct 8 ms 3448 KB Output is correct
12 Correct 5 ms 3448 KB Output is correct
13 Correct 7 ms 3448 KB Output is correct
14 Correct 7 ms 3448 KB Output is correct
15 Correct 8 ms 3448 KB Output is correct
16 Correct 9 ms 3500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 3448 KB Output is correct
2 Correct 6 ms 3448 KB Output is correct
3 Correct 6 ms 3448 KB Output is correct
4 Correct 10 ms 3448 KB Output is correct
5 Correct 8 ms 3448 KB Output is correct
6 Correct 9 ms 3448 KB Output is correct
7 Correct 9 ms 3448 KB Output is correct
8 Correct 8 ms 3476 KB Output is correct
9 Correct 10 ms 3448 KB Output is correct
10 Correct 9 ms 3448 KB Output is correct
11 Correct 8 ms 3448 KB Output is correct
12 Correct 5 ms 3448 KB Output is correct
13 Correct 7 ms 3448 KB Output is correct
14 Correct 7 ms 3448 KB Output is correct
15 Correct 8 ms 3448 KB Output is correct
16 Correct 9 ms 3500 KB Output is correct
17 Correct 42 ms 3576 KB Output is correct
18 Correct 46 ms 3448 KB Output is correct
19 Correct 27 ms 3548 KB Output is correct
20 Correct 5 ms 3448 KB Output is correct
21 Correct 21 ms 3448 KB Output is correct
22 Correct 24 ms 3448 KB Output is correct
23 Correct 55 ms 3448 KB Output is correct
24 Correct 48 ms 3548 KB Output is correct
25 Correct 41 ms 3528 KB Output is correct
26 Correct 18 ms 3484 KB Output is correct
27 Correct 18 ms 3448 KB Output is correct
28 Correct 15 ms 3576 KB Output is correct
29 Correct 60 ms 3576 KB Output is correct
30 Correct 30 ms 3524 KB Output is correct
31 Correct 9 ms 3448 KB Output is correct
32 Correct 36 ms 3448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 3448 KB Output is correct
2 Correct 6 ms 3448 KB Output is correct
3 Correct 6 ms 3448 KB Output is correct
4 Correct 10 ms 3448 KB Output is correct
5 Correct 8 ms 3448 KB Output is correct
6 Correct 9 ms 3448 KB Output is correct
7 Correct 9 ms 3448 KB Output is correct
8 Correct 8 ms 3476 KB Output is correct
9 Correct 10 ms 3448 KB Output is correct
10 Correct 9 ms 3448 KB Output is correct
11 Correct 8 ms 3448 KB Output is correct
12 Correct 5 ms 3448 KB Output is correct
13 Correct 7 ms 3448 KB Output is correct
14 Correct 7 ms 3448 KB Output is correct
15 Correct 8 ms 3448 KB Output is correct
16 Correct 9 ms 3500 KB Output is correct
17 Correct 42 ms 3576 KB Output is correct
18 Correct 46 ms 3448 KB Output is correct
19 Correct 27 ms 3548 KB Output is correct
20 Correct 5 ms 3448 KB Output is correct
21 Correct 21 ms 3448 KB Output is correct
22 Correct 24 ms 3448 KB Output is correct
23 Correct 55 ms 3448 KB Output is correct
24 Correct 48 ms 3548 KB Output is correct
25 Correct 41 ms 3528 KB Output is correct
26 Correct 18 ms 3484 KB Output is correct
27 Correct 18 ms 3448 KB Output is correct
28 Correct 15 ms 3576 KB Output is correct
29 Correct 60 ms 3576 KB Output is correct
30 Correct 30 ms 3524 KB Output is correct
31 Correct 9 ms 3448 KB Output is correct
32 Correct 36 ms 3448 KB Output is correct
33 Execution timed out 3043 ms 7724 KB Time limit exceeded
34 Halted 0 ms 0 KB -