# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
124009 | 2019-07-02T10:53:13 Z | arnold518 | Cats or Dogs (JOI18_catdog) | C++14 | 3000 ms | 8288 KB |
#include "catdog.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 1e5; const int MAXQ = 1e5; const int INF = 987654321; int N, A[MAXN+10]; int dp[MAXN+10][3]; vector<int> adj[MAXN+10]; void initialize(int n, vector<int> A, vector<int> B) { int i, j; N=n; for(i=0; i<N-1; i++) { adj[A[i]].push_back(B[i]); adj[B[i]].push_back(A[i]); } } void dfs(int now, int par) { int i, j; for(int nxt : adj[now]) { if(nxt==par) continue; dfs(nxt, now); if(A[now]!=2) dp[now][1]+=min(dp[nxt][1], dp[nxt][2]+1); if(A[now]!=1) dp[now][2]+=min(dp[nxt][1]+1, dp[nxt][2]); } if(A[now]==1) dp[now][2]=INF; if(A[now]==2) dp[now][1]=INF; } int solve() { memset(dp, 0, sizeof(dp)); dfs(1, -1); return min(dp[1][2], dp[1][1]); } int cat(int v) { A[v]=1; return solve(); } int dog(int v) { A[v]=2; return solve(); } int neighbor(int v) { A[v]=0; return solve(); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 3832 KB | Output is correct |
2 | Correct | 7 ms | 3832 KB | Output is correct |
3 | Correct | 8 ms | 3832 KB | Output is correct |
4 | Correct | 12 ms | 3832 KB | Output is correct |
5 | Correct | 11 ms | 3832 KB | Output is correct |
6 | Correct | 11 ms | 3832 KB | Output is correct |
7 | Correct | 11 ms | 3832 KB | Output is correct |
8 | Correct | 11 ms | 3836 KB | Output is correct |
9 | Correct | 11 ms | 3860 KB | Output is correct |
10 | Correct | 11 ms | 3832 KB | Output is correct |
11 | Correct | 9 ms | 3832 KB | Output is correct |
12 | Correct | 5 ms | 3832 KB | Output is correct |
13 | Correct | 8 ms | 3832 KB | Output is correct |
14 | Correct | 9 ms | 3832 KB | Output is correct |
15 | Correct | 10 ms | 3880 KB | Output is correct |
16 | Correct | 12 ms | 3832 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 3832 KB | Output is correct |
2 | Correct | 7 ms | 3832 KB | Output is correct |
3 | Correct | 8 ms | 3832 KB | Output is correct |
4 | Correct | 12 ms | 3832 KB | Output is correct |
5 | Correct | 11 ms | 3832 KB | Output is correct |
6 | Correct | 11 ms | 3832 KB | Output is correct |
7 | Correct | 11 ms | 3832 KB | Output is correct |
8 | Correct | 11 ms | 3836 KB | Output is correct |
9 | Correct | 11 ms | 3860 KB | Output is correct |
10 | Correct | 11 ms | 3832 KB | Output is correct |
11 | Correct | 9 ms | 3832 KB | Output is correct |
12 | Correct | 5 ms | 3832 KB | Output is correct |
13 | Correct | 8 ms | 3832 KB | Output is correct |
14 | Correct | 9 ms | 3832 KB | Output is correct |
15 | Correct | 10 ms | 3880 KB | Output is correct |
16 | Correct | 12 ms | 3832 KB | Output is correct |
17 | Correct | 61 ms | 3968 KB | Output is correct |
18 | Correct | 66 ms | 3832 KB | Output is correct |
19 | Correct | 38 ms | 3940 KB | Output is correct |
20 | Correct | 6 ms | 3832 KB | Output is correct |
21 | Correct | 31 ms | 3832 KB | Output is correct |
22 | Correct | 33 ms | 3960 KB | Output is correct |
23 | Correct | 79 ms | 3980 KB | Output is correct |
24 | Correct | 65 ms | 3960 KB | Output is correct |
25 | Correct | 54 ms | 3916 KB | Output is correct |
26 | Correct | 25 ms | 3832 KB | Output is correct |
27 | Correct | 24 ms | 3832 KB | Output is correct |
28 | Correct | 19 ms | 3960 KB | Output is correct |
29 | Correct | 79 ms | 3996 KB | Output is correct |
30 | Correct | 39 ms | 3832 KB | Output is correct |
31 | Correct | 12 ms | 3960 KB | Output is correct |
32 | Correct | 48 ms | 3832 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 3832 KB | Output is correct |
2 | Correct | 7 ms | 3832 KB | Output is correct |
3 | Correct | 8 ms | 3832 KB | Output is correct |
4 | Correct | 12 ms | 3832 KB | Output is correct |
5 | Correct | 11 ms | 3832 KB | Output is correct |
6 | Correct | 11 ms | 3832 KB | Output is correct |
7 | Correct | 11 ms | 3832 KB | Output is correct |
8 | Correct | 11 ms | 3836 KB | Output is correct |
9 | Correct | 11 ms | 3860 KB | Output is correct |
10 | Correct | 11 ms | 3832 KB | Output is correct |
11 | Correct | 9 ms | 3832 KB | Output is correct |
12 | Correct | 5 ms | 3832 KB | Output is correct |
13 | Correct | 8 ms | 3832 KB | Output is correct |
14 | Correct | 9 ms | 3832 KB | Output is correct |
15 | Correct | 10 ms | 3880 KB | Output is correct |
16 | Correct | 12 ms | 3832 KB | Output is correct |
17 | Correct | 61 ms | 3968 KB | Output is correct |
18 | Correct | 66 ms | 3832 KB | Output is correct |
19 | Correct | 38 ms | 3940 KB | Output is correct |
20 | Correct | 6 ms | 3832 KB | Output is correct |
21 | Correct | 31 ms | 3832 KB | Output is correct |
22 | Correct | 33 ms | 3960 KB | Output is correct |
23 | Correct | 79 ms | 3980 KB | Output is correct |
24 | Correct | 65 ms | 3960 KB | Output is correct |
25 | Correct | 54 ms | 3916 KB | Output is correct |
26 | Correct | 25 ms | 3832 KB | Output is correct |
27 | Correct | 24 ms | 3832 KB | Output is correct |
28 | Correct | 19 ms | 3960 KB | Output is correct |
29 | Correct | 79 ms | 3996 KB | Output is correct |
30 | Correct | 39 ms | 3832 KB | Output is correct |
31 | Correct | 12 ms | 3960 KB | Output is correct |
32 | Correct | 48 ms | 3832 KB | Output is correct |
33 | Execution timed out | 3041 ms | 8288 KB | Time limit exceeded |
34 | Halted | 0 ms | 0 KB | - |