답안 #125490

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
125490 2019-07-05T13:25:50 Z arnold518 Cats or Dogs (JOI18_catdog) C++14
38 / 100
3000 ms 8100 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);

        dp[now][1]+=min(dp[nxt][1], dp[nxt][2]+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

catdog.cpp: In function 'void initialize(int, std::vector<int>, std::vector<int>)':
catdog.cpp:19:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
catdog.cpp: In function 'void dfs(int, int)':
catdog.cpp:31:9: warning: unused variable 'i' [-Wunused-variable]
     int i, j;
         ^
catdog.cpp:31:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 3832 KB Output is correct
2 Correct 7 ms 3832 KB Output is correct
3 Correct 8 ms 3704 KB Output is correct
4 Correct 11 ms 3832 KB Output is correct
5 Correct 11 ms 3832 KB Output is correct
6 Correct 12 ms 3832 KB Output is correct
7 Correct 11 ms 3832 KB Output is correct
8 Correct 12 ms 3832 KB Output is correct
9 Correct 13 ms 3796 KB Output is correct
10 Correct 13 ms 3832 KB Output is correct
11 Correct 9 ms 3836 KB Output is correct
12 Correct 5 ms 3900 KB Output is correct
13 Correct 10 ms 3832 KB Output is correct
14 Correct 9 ms 3832 KB Output is correct
15 Correct 9 ms 3832 KB Output is correct
16 Correct 13 ms 3960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 3832 KB Output is correct
2 Correct 7 ms 3832 KB Output is correct
3 Correct 8 ms 3704 KB Output is correct
4 Correct 11 ms 3832 KB Output is correct
5 Correct 11 ms 3832 KB Output is correct
6 Correct 12 ms 3832 KB Output is correct
7 Correct 11 ms 3832 KB Output is correct
8 Correct 12 ms 3832 KB Output is correct
9 Correct 13 ms 3796 KB Output is correct
10 Correct 13 ms 3832 KB Output is correct
11 Correct 9 ms 3836 KB Output is correct
12 Correct 5 ms 3900 KB Output is correct
13 Correct 10 ms 3832 KB Output is correct
14 Correct 9 ms 3832 KB Output is correct
15 Correct 9 ms 3832 KB Output is correct
16 Correct 13 ms 3960 KB Output is correct
17 Correct 56 ms 3832 KB Output is correct
18 Correct 61 ms 3960 KB Output is correct
19 Correct 37 ms 3960 KB Output is correct
20 Correct 6 ms 3832 KB Output is correct
21 Correct 30 ms 3800 KB Output is correct
22 Correct 33 ms 3900 KB Output is correct
23 Correct 73 ms 3908 KB Output is correct
24 Correct 64 ms 3960 KB Output is correct
25 Correct 56 ms 3960 KB Output is correct
26 Correct 24 ms 3832 KB Output is correct
27 Correct 27 ms 3948 KB Output is correct
28 Correct 22 ms 3960 KB Output is correct
29 Correct 96 ms 3960 KB Output is correct
30 Correct 42 ms 3832 KB Output is correct
31 Correct 12 ms 3832 KB Output is correct
32 Correct 49 ms 3832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 3832 KB Output is correct
2 Correct 7 ms 3832 KB Output is correct
3 Correct 8 ms 3704 KB Output is correct
4 Correct 11 ms 3832 KB Output is correct
5 Correct 11 ms 3832 KB Output is correct
6 Correct 12 ms 3832 KB Output is correct
7 Correct 11 ms 3832 KB Output is correct
8 Correct 12 ms 3832 KB Output is correct
9 Correct 13 ms 3796 KB Output is correct
10 Correct 13 ms 3832 KB Output is correct
11 Correct 9 ms 3836 KB Output is correct
12 Correct 5 ms 3900 KB Output is correct
13 Correct 10 ms 3832 KB Output is correct
14 Correct 9 ms 3832 KB Output is correct
15 Correct 9 ms 3832 KB Output is correct
16 Correct 13 ms 3960 KB Output is correct
17 Correct 56 ms 3832 KB Output is correct
18 Correct 61 ms 3960 KB Output is correct
19 Correct 37 ms 3960 KB Output is correct
20 Correct 6 ms 3832 KB Output is correct
21 Correct 30 ms 3800 KB Output is correct
22 Correct 33 ms 3900 KB Output is correct
23 Correct 73 ms 3908 KB Output is correct
24 Correct 64 ms 3960 KB Output is correct
25 Correct 56 ms 3960 KB Output is correct
26 Correct 24 ms 3832 KB Output is correct
27 Correct 27 ms 3948 KB Output is correct
28 Correct 22 ms 3960 KB Output is correct
29 Correct 96 ms 3960 KB Output is correct
30 Correct 42 ms 3832 KB Output is correct
31 Correct 12 ms 3832 KB Output is correct
32 Correct 49 ms 3832 KB Output is correct
33 Execution timed out 3023 ms 8100 KB Time limit exceeded
34 Halted 0 ms 0 KB -