답안 #132181

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
132181 2019-07-18T12:04:18 Z mlyean00 열대 식물원 (Tropical Garden) (IOI11_garden) C++14
69 / 100
5000 ms 92140 KB
#include "garden.h"
#include "gardenlib.h"

#include <bits/stdc++.h>

using namespace std;
using adj_list = vector<vector<int>>;

const int MAX = 1'000'000'000;

void count_routes(int N, int M, int P, int R[][2], int Q, int G[]) {
    adj_list g(N);
    for (int i = 0; i < M; ++i) {
        g[R[i][0]].push_back(R[i][1]);
        g[R[i][1]].push_back(R[i][0]);
    }

    int k = __lg(MAX);
    vector<vector<pair<int, int>>> st0(N, vector<pair<int, int>>(k + 1));
    vector<vector<pair<int, int>>> st1(N, vector<pair<int, int>>(k + 1));

    for (int u = 0; u < N; ++u) {
        if (g[u].empty()) continue;

        st0[u][0] = {g[u].size() == 1 ? g[u][0] : g[u][1], u};
        st1[u][0] = {g[u][0], u};
    }

    for (int i = 1; i <= k; ++i) {
        for (int u = 0; u < N; ++u) {
            if (g[u].empty()) continue;
            int v, p;

            tie(v, p) = st0[u][i - 1];
            st0[u][i] = p == g[v][0] ? st0[v][i - 1] : st1[v][i - 1];

            tie(v, p) = st1[u][i - 1];
            st1[u][i] = p == g[v][0] ? st0[v][i - 1] : st1[v][i - 1];
        }
    }

    for (int q = 0; q < Q; ++q) {
        int ans = 0;
        for (int i = 0; i < N; ++i) {
            if (g[i].empty()) continue;
            int u = i, p = -1;
            for (int j = G[q]; j; j -= j & -j) {
                int s = __builtin_ctz(j);
                tie(u, p) = g[u][0] == p ? st0[u][s] : st1[u][s];
            }
            if (u == P) ++ans;
        }
        answer(ans);
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 760 KB Output is correct
2 Correct 3 ms 888 KB Output is correct
3 Correct 3 ms 888 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 4 ms 892 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 888 KB Output is correct
9 Correct 6 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 760 KB Output is correct
2 Correct 3 ms 888 KB Output is correct
3 Correct 3 ms 888 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 4 ms 892 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 888 KB Output is correct
9 Correct 6 ms 1144 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 49 ms 14072 KB Output is correct
12 Correct 104 ms 23516 KB Output is correct
13 Correct 353 ms 52320 KB Output is correct
14 Correct 475 ms 83192 KB Output is correct
15 Correct 457 ms 84072 KB Output is correct
16 Correct 356 ms 57140 KB Output is correct
17 Correct 261 ms 48308 KB Output is correct
18 Correct 98 ms 23544 KB Output is correct
19 Correct 475 ms 83084 KB Output is correct
20 Correct 459 ms 84080 KB Output is correct
21 Correct 345 ms 56972 KB Output is correct
22 Correct 271 ms 48204 KB Output is correct
23 Correct 604 ms 92140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 760 KB Output is correct
2 Correct 3 ms 888 KB Output is correct
3 Correct 3 ms 888 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 4 ms 892 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 888 KB Output is correct
9 Correct 6 ms 1144 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 49 ms 14072 KB Output is correct
12 Correct 104 ms 23516 KB Output is correct
13 Correct 353 ms 52320 KB Output is correct
14 Correct 475 ms 83192 KB Output is correct
15 Correct 457 ms 84072 KB Output is correct
16 Correct 356 ms 57140 KB Output is correct
17 Correct 261 ms 48308 KB Output is correct
18 Correct 98 ms 23544 KB Output is correct
19 Correct 475 ms 83084 KB Output is correct
20 Correct 459 ms 84080 KB Output is correct
21 Correct 345 ms 56972 KB Output is correct
22 Correct 271 ms 48204 KB Output is correct
23 Correct 604 ms 92140 KB Output is correct
24 Correct 9 ms 376 KB Output is correct
25 Execution timed out 5029 ms 14148 KB Time limit exceeded
26 Halted 0 ms 0 KB -