# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1090041 | 2024-09-17T16:00:16 Z | VMaksimoski008 | Cats or Dogs (JOI18_catdog) | C++17 | 3000 ms | 7368 KB |
#include "catdog.h" #include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int n, dp[maxn][2]; vector<int> graph[maxn], val(maxn); void reset() { for(int i=1; i<=n; i++) dp[i][0] = dp[i][1] = dp[i][2] = 1e6; } int query() { if(val[1] == 1) return dp[1][1]; if(val[1] == 2) return dp[1][2]; return min(dp[1][1], dp[1][2]); } void dfs(int u, int p) { if(val[u] != 1) dp[u][2] = 0; if(val[u] != 2) dp[u][1] = 0; for(int &v : graph[u]) { if(v == p) continue; dfs(v, u); if(val[u] != 1) dp[u][2] += min(dp[v][2], dp[v][1] + 1); if(val[u] != 2) dp[u][1] += min(dp[v][1], dp[v][2] + 1); } } void initialize(int N, vector<int> A, vector<int> B) { n = N; for(int i=0; i<n-1; i++) { graph[A[i]].push_back(B[i]); graph[B[i]].push_back(A[i]); } } int cat(int v) { val[v] = 1; reset(); dfs(1, 1); return query(); } int dog(int v) { val[v] = 2; reset(); dfs(1, 1); return query(); } int neighbor(int v) { val[v] = 0; reset(); dfs(1, 1); return query(); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 3164 KB | Output is correct |
2 | Correct | 2 ms | 3192 KB | Output is correct |
3 | Correct | 1 ms | 3164 KB | Output is correct |
4 | Correct | 1 ms | 3164 KB | Output is correct |
5 | Correct | 1 ms | 3164 KB | Output is correct |
6 | Correct | 1 ms | 3164 KB | Output is correct |
7 | Correct | 1 ms | 3164 KB | Output is correct |
8 | Correct | 1 ms | 3164 KB | Output is correct |
9 | Correct | 1 ms | 3164 KB | Output is correct |
10 | Correct | 1 ms | 3196 KB | Output is correct |
11 | Correct | 1 ms | 3164 KB | Output is correct |
12 | Correct | 1 ms | 3164 KB | Output is correct |
13 | Correct | 1 ms | 3164 KB | Output is correct |
14 | Correct | 1 ms | 3164 KB | Output is correct |
15 | Correct | 1 ms | 3164 KB | Output is correct |
16 | Correct | 1 ms | 3164 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 3164 KB | Output is correct |
2 | Correct | 2 ms | 3192 KB | Output is correct |
3 | Correct | 1 ms | 3164 KB | Output is correct |
4 | Correct | 1 ms | 3164 KB | Output is correct |
5 | Correct | 1 ms | 3164 KB | Output is correct |
6 | Correct | 1 ms | 3164 KB | Output is correct |
7 | Correct | 1 ms | 3164 KB | Output is correct |
8 | Correct | 1 ms | 3164 KB | Output is correct |
9 | Correct | 1 ms | 3164 KB | Output is correct |
10 | Correct | 1 ms | 3196 KB | Output is correct |
11 | Correct | 1 ms | 3164 KB | Output is correct |
12 | Correct | 1 ms | 3164 KB | Output is correct |
13 | Correct | 1 ms | 3164 KB | Output is correct |
14 | Correct | 1 ms | 3164 KB | Output is correct |
15 | Correct | 1 ms | 3164 KB | Output is correct |
16 | Correct | 1 ms | 3164 KB | Output is correct |
17 | Correct | 6 ms | 3248 KB | Output is correct |
18 | Correct | 8 ms | 3104 KB | Output is correct |
19 | Correct | 5 ms | 3204 KB | Output is correct |
20 | Correct | 2 ms | 3160 KB | Output is correct |
21 | Correct | 2 ms | 3160 KB | Output is correct |
22 | Correct | 2 ms | 3164 KB | Output is correct |
23 | Correct | 9 ms | 3256 KB | Output is correct |
24 | Correct | 8 ms | 3160 KB | Output is correct |
25 | Correct | 5 ms | 3164 KB | Output is correct |
26 | Correct | 3 ms | 3164 KB | Output is correct |
27 | Correct | 2 ms | 3164 KB | Output is correct |
28 | Correct | 3 ms | 3164 KB | Output is correct |
29 | Correct | 11 ms | 3164 KB | Output is correct |
30 | Correct | 3 ms | 3164 KB | Output is correct |
31 | Correct | 2 ms | 3164 KB | Output is correct |
32 | Correct | 4 ms | 3164 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 3164 KB | Output is correct |
2 | Correct | 2 ms | 3192 KB | Output is correct |
3 | Correct | 1 ms | 3164 KB | Output is correct |
4 | Correct | 1 ms | 3164 KB | Output is correct |
5 | Correct | 1 ms | 3164 KB | Output is correct |
6 | Correct | 1 ms | 3164 KB | Output is correct |
7 | Correct | 1 ms | 3164 KB | Output is correct |
8 | Correct | 1 ms | 3164 KB | Output is correct |
9 | Correct | 1 ms | 3164 KB | Output is correct |
10 | Correct | 1 ms | 3196 KB | Output is correct |
11 | Correct | 1 ms | 3164 KB | Output is correct |
12 | Correct | 1 ms | 3164 KB | Output is correct |
13 | Correct | 1 ms | 3164 KB | Output is correct |
14 | Correct | 1 ms | 3164 KB | Output is correct |
15 | Correct | 1 ms | 3164 KB | Output is correct |
16 | Correct | 1 ms | 3164 KB | Output is correct |
17 | Correct | 6 ms | 3248 KB | Output is correct |
18 | Correct | 8 ms | 3104 KB | Output is correct |
19 | Correct | 5 ms | 3204 KB | Output is correct |
20 | Correct | 2 ms | 3160 KB | Output is correct |
21 | Correct | 2 ms | 3160 KB | Output is correct |
22 | Correct | 2 ms | 3164 KB | Output is correct |
23 | Correct | 9 ms | 3256 KB | Output is correct |
24 | Correct | 8 ms | 3160 KB | Output is correct |
25 | Correct | 5 ms | 3164 KB | Output is correct |
26 | Correct | 3 ms | 3164 KB | Output is correct |
27 | Correct | 2 ms | 3164 KB | Output is correct |
28 | Correct | 3 ms | 3164 KB | Output is correct |
29 | Correct | 11 ms | 3164 KB | Output is correct |
30 | Correct | 3 ms | 3164 KB | Output is correct |
31 | Correct | 2 ms | 3164 KB | Output is correct |
32 | Correct | 4 ms | 3164 KB | Output is correct |
33 | Execution timed out | 3036 ms | 7368 KB | Time limit exceeded |
34 | Halted | 0 ms | 0 KB | - |