답안 #1017882

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1017882 2024-07-09T10:59:39 Z Sho10 열대 식물원 (Tropical Garden) (IOI11_garden) C++17
69 / 100
5000 ms 41304 KB
#include "garden.h"
#include "gardenlib.h"
#include <map>
#include <set>
#include <vector>
#include <iostream>

using namespace std;

int adj[150000][3];
int par[300000][30];

void count_routes(int N, int M, int P, int R[][2], int Q, int G[]) {
    for (int i = 0; i < M; i++) {
        int a = R[i][0], b = R[i][1];
        if (adj[a][2] < 2) adj[a][adj[a][2]++] = b;
        if (adj[b][2] < 2) adj[b][adj[b][2]++] = a;
    }

    for (int i = 0; i < N; i++) {
        if (adj[i][2] == 0) continue;
        if (adj[i][2] == 1) adj[i][1] = adj[i][0];

        if (adj[adj[i][0]][0] == i) par[i][0] = 150000 + adj[i][0];
        else par[i][0] = adj[i][0];
        if (adj[adj[i][1]][0] == i) par[150000 + i][0] = 150000 + adj[i][1];
        else par[150000 + i][0] = adj[i][1];
    }

    for (int j = 1; j < 30; j++) {
        for (int i = 0; i < N; i++) {
            par[i][j] = par[par[i][j - 1]][j - 1];
            par[150000 + i][j] = par[par[150000 + i][j - 1]][j - 1];
        }
    }

    for (int it = 0; it < Q; it++) {
        int res = 0;
        for (int i = 0; i < N; i++) {
            if (adj[i][2] == 0) continue;
            int c = i;
            for (int j = 0, k = G[it]; j < 30; j++, k >>= 1) {
                if (k & 1) c = par[c][j];
            }
            if (c % 150000 == P) res++;
        }

        answer(res);
    }
}


# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4544 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4952 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4544 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4952 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4592 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 9 ms 13168 KB Output is correct
12 Correct 16 ms 17500 KB Output is correct
13 Correct 30 ms 28212 KB Output is correct
14 Correct 49 ms 41248 KB Output is correct
15 Correct 46 ms 41304 KB Output is correct
16 Correct 39 ms 30804 KB Output is correct
17 Correct 33 ms 26712 KB Output is correct
18 Correct 15 ms 17496 KB Output is correct
19 Correct 50 ms 41048 KB Output is correct
20 Correct 49 ms 41300 KB Output is correct
21 Correct 37 ms 30764 KB Output is correct
22 Correct 32 ms 26756 KB Output is correct
23 Correct 59 ms 41296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4544 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4952 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4592 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 9 ms 13168 KB Output is correct
12 Correct 16 ms 17500 KB Output is correct
13 Correct 30 ms 28212 KB Output is correct
14 Correct 49 ms 41248 KB Output is correct
15 Correct 46 ms 41304 KB Output is correct
16 Correct 39 ms 30804 KB Output is correct
17 Correct 33 ms 26712 KB Output is correct
18 Correct 15 ms 17496 KB Output is correct
19 Correct 50 ms 41048 KB Output is correct
20 Correct 49 ms 41300 KB Output is correct
21 Correct 37 ms 30764 KB Output is correct
22 Correct 32 ms 26756 KB Output is correct
23 Correct 59 ms 41296 KB Output is correct
24 Correct 7 ms 4444 KB Output is correct
25 Correct 2654 ms 13164 KB Output is correct
26 Execution timed out 5029 ms 17608 KB Time limit exceeded
27 Halted 0 ms 0 KB -