답안 #159919

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
159919 2019-10-25T12:04:58 Z dolphingarlic 열대 식물원 (Tropical Garden) (IOI11_garden) C++14
100 / 100
3606 ms 46968 KB
#include "garden.h"
#include <bits/stdc++.h>
#include "gardenlib.h"

using namespace std;

typedef pair<int, int> pii;

const int MX = 200011;
vector<int> adj[MX * 2], g[MX * 2];

int F[MX * 2][2], c[2];

void connect(int u, int v, int N) {
    if (adj[u][0] == v || adj[u][0] == v - N) u = u + N;
    g[u].push_back(v);
}
void dfs(int u, int p, int it) {
    for (int i = 0; i < g[u].size(); ++i) {
        int v = g[u][i];
        if (v == p) {
            c[it] = F[u][it] + 1;
        } else if (F[v][it] == -1) {
            F[v][it] = F[u][it] + 1;
            dfs(g[u][i], p, it);
        }
    }
}
void count_routes(int N, int M, int P, int R[][2], int Q, int G[]) {
    memset(F, -1, sizeof F);
    for (int i = 0; i < M; ++i) {
        adj[R[i][0]].push_back(R[i][1]);
        adj[R[i][1]].push_back(R[i][0]);
    }
    for (int i = 0; i < N; ++i) {
        while (adj[i].size() > 2) adj[i].pop_back();
        connect(adj[i][0], i, N);
        if (adj[i].size() == 2) {
            connect(adj[i][1], i + N, N);
        } else {
            connect(adj[i][0], i + N, N);
        }
    }

    F[P][0] = 0;
    dfs(P, P, 0);
    F[P + N][1] = 0;
    dfs(P + N, P + N, 1);

    for (int k = 0; k < Q; k++) {
        int res = 0;
        for (int i = 0; i < N; ++i) {
            for (int it = 0; it < 2; it++) {
                if (F[i][it] == -1) continue;
                int rem = G[k];
                if (rem < F[i][it]) continue;
                rem -= F[i][it];
                if (rem == 0 || (c[it] && rem % c[it] == 0)) {
                    res++;
                    break;
                }
            }
        }
        answer(res);
    }
}

Compilation message

garden.cpp: In function 'void dfs(int, int, int)':
garden.cpp:19:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < g[u].size(); ++i) {
                     ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 22388 KB Output is correct
2 Correct 23 ms 22392 KB Output is correct
3 Correct 23 ms 22392 KB Output is correct
4 Correct 21 ms 22264 KB Output is correct
5 Correct 21 ms 22292 KB Output is correct
6 Correct 22 ms 22520 KB Output is correct
7 Correct 22 ms 22264 KB Output is correct
8 Correct 22 ms 22380 KB Output is correct
9 Correct 24 ms 22552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 22388 KB Output is correct
2 Correct 23 ms 22392 KB Output is correct
3 Correct 23 ms 22392 KB Output is correct
4 Correct 21 ms 22264 KB Output is correct
5 Correct 21 ms 22292 KB Output is correct
6 Correct 22 ms 22520 KB Output is correct
7 Correct 22 ms 22264 KB Output is correct
8 Correct 22 ms 22380 KB Output is correct
9 Correct 24 ms 22552 KB Output is correct
10 Correct 22 ms 22236 KB Output is correct
11 Correct 35 ms 24208 KB Output is correct
12 Correct 57 ms 25360 KB Output is correct
13 Correct 81 ms 41520 KB Output is correct
14 Correct 169 ms 32296 KB Output is correct
15 Correct 211 ms 32548 KB Output is correct
16 Correct 163 ms 30176 KB Output is correct
17 Correct 162 ms 29000 KB Output is correct
18 Correct 61 ms 25336 KB Output is correct
19 Correct 223 ms 32312 KB Output is correct
20 Correct 211 ms 32548 KB Output is correct
21 Correct 166 ms 29944 KB Output is correct
22 Correct 151 ms 28976 KB Output is correct
23 Correct 187 ms 33280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 22388 KB Output is correct
2 Correct 23 ms 22392 KB Output is correct
3 Correct 23 ms 22392 KB Output is correct
4 Correct 21 ms 22264 KB Output is correct
5 Correct 21 ms 22292 KB Output is correct
6 Correct 22 ms 22520 KB Output is correct
7 Correct 22 ms 22264 KB Output is correct
8 Correct 22 ms 22380 KB Output is correct
9 Correct 24 ms 22552 KB Output is correct
10 Correct 22 ms 22236 KB Output is correct
11 Correct 35 ms 24208 KB Output is correct
12 Correct 57 ms 25360 KB Output is correct
13 Correct 81 ms 41520 KB Output is correct
14 Correct 169 ms 32296 KB Output is correct
15 Correct 211 ms 32548 KB Output is correct
16 Correct 163 ms 30176 KB Output is correct
17 Correct 162 ms 29000 KB Output is correct
18 Correct 61 ms 25336 KB Output is correct
19 Correct 223 ms 32312 KB Output is correct
20 Correct 211 ms 32548 KB Output is correct
21 Correct 166 ms 29944 KB Output is correct
22 Correct 151 ms 28976 KB Output is correct
23 Correct 187 ms 33280 KB Output is correct
24 Correct 18 ms 22364 KB Output is correct
25 Correct 182 ms 24212 KB Output is correct
26 Correct 244 ms 25400 KB Output is correct
27 Correct 2120 ms 41720 KB Output is correct
28 Correct 1927 ms 32376 KB Output is correct
29 Correct 2529 ms 32584 KB Output is correct
30 Correct 1421 ms 30072 KB Output is correct
31 Correct 1526 ms 29040 KB Output is correct
32 Correct 280 ms 25376 KB Output is correct
33 Correct 1930 ms 32488 KB Output is correct
34 Correct 2403 ms 32560 KB Output is correct
35 Correct 1407 ms 29932 KB Output is correct
36 Correct 2255 ms 29056 KB Output is correct
37 Correct 1468 ms 33392 KB Output is correct
38 Correct 3606 ms 46968 KB Output is correct