답안 #711617

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
711617 2023-03-17T09:51:46 Z lorenzoferrari 열대 식물원 (Tropical Garden) (IOI11_garden) C++17
100 / 100
4290 ms 51164 KB
#pragma GCC target("avx2")
#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using LL = long long;

static constexpr int LG = 31;
static constexpr int M = 3e5;

static int up[LG][M];
bitset<M> good;

inline void build(int n, vector<int> to, int p) {
    good[2*p] = good[2*p+1] = 1;
    for (int i = 0; i < n; ++i) {
        up[0][i] = to[i];
        if (good[to[i]]) good[i] = 1;
    }
    for (int j = 1; j < LG; ++j) {
        for (int i = 0; i < n; ++i) {
            up[j][i] = up[j-1][up[j-1][i]];
            if (good[up[j][i]]) good[i] = 1;
        }
    }
}

void answer(int);

void count_routes(int n, int m, int p, int r[][2], int q, int g[]) {
    vector<vector<array<int, 2>>> adj(n);
    for (int i = 0; i < m; ++i) {
        int a = r[i][0];
        int b = r[i][1];
        adj[a].push_back({b, i});
        adj[b].push_back({a, i});
    }
    // split each node v into two:
    // a) v' = 2*v: v, doesn't come from best path
    // b) v'' = 2*v+1: v, does come from best path
    vector<int> to(2*n);
    for (int i = 0; i < n; ++i) {
        int u = adj[i][0][0];
        to[2*i] = 2*u + (adj[u][0][1] == adj[i][0][1]);
        if ((int)adj[i].size() == 1) {
            to[2*i+1] = to[2*i];
        } else {
            u = adj[i][1][0];
            to[2*i+1] = 2*u + (adj[u][0][1] == adj[i][1][1]);
        }
    }

    build(2*n, to, p);

    vector<array<int, 2>> ks(q);
    for (int i = 0; i < q; ++i) {
        ks[i] = {g[i], i};
    }
    sort(begin(ks), end(ks));
    for (int i = q-1; i > 0; --i) {
        ks[i][0] -= ks[i-1][0];
    }
    vector<int> cur;
    for (int i = 0; i < 2*n; i += 2) {
        if (good[i]) {
            cur.push_back(i);
        }
    }
    vector<int> ans(q);
    for (auto [k, i] : ks) {
        for (int j = 0; j < LG; ++j) {
            if (k & (1 << j)) {
                for (int& v : cur) {
                    v = up[j][v];
                }
            }
        }
        for (int& v : cur) {
            ans[i] += (v/2 == p);
        }
    }
    for (int i = 0; i < q; ++i) {
        answer(ans[i]);
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 1 ms 824 KB Output is correct
3 Correct 1 ms 852 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 852 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 3 ms 1160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 1 ms 824 KB Output is correct
3 Correct 1 ms 852 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 852 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 3 ms 1160 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 15 ms 8036 KB Output is correct
12 Correct 36 ms 13772 KB Output is correct
13 Correct 47 ms 28988 KB Output is correct
14 Correct 101 ms 46492 KB Output is correct
15 Correct 88 ms 47744 KB Output is correct
16 Correct 71 ms 33704 KB Output is correct
17 Correct 68 ms 29344 KB Output is correct
18 Correct 32 ms 13780 KB Output is correct
19 Correct 104 ms 46504 KB Output is correct
20 Correct 101 ms 47684 KB Output is correct
21 Correct 79 ms 33632 KB Output is correct
22 Correct 70 ms 29092 KB Output is correct
23 Correct 96 ms 51164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 1 ms 824 KB Output is correct
3 Correct 1 ms 852 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 852 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 3 ms 1160 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 15 ms 8036 KB Output is correct
12 Correct 36 ms 13772 KB Output is correct
13 Correct 47 ms 28988 KB Output is correct
14 Correct 101 ms 46492 KB Output is correct
15 Correct 88 ms 47744 KB Output is correct
16 Correct 71 ms 33704 KB Output is correct
17 Correct 68 ms 29344 KB Output is correct
18 Correct 32 ms 13780 KB Output is correct
19 Correct 104 ms 46504 KB Output is correct
20 Correct 101 ms 47684 KB Output is correct
21 Correct 79 ms 33632 KB Output is correct
22 Correct 70 ms 29092 KB Output is correct
23 Correct 96 ms 51164 KB Output is correct
24 Correct 2 ms 596 KB Output is correct
25 Correct 35 ms 8080 KB Output is correct
26 Correct 35 ms 13864 KB Output is correct
27 Correct 1266 ms 29044 KB Output is correct
28 Correct 387 ms 46556 KB Output is correct
29 Correct 1755 ms 47852 KB Output is correct
30 Correct 1213 ms 33808 KB Output is correct
31 Correct 1004 ms 29572 KB Output is correct
32 Correct 41 ms 13848 KB Output is correct
33 Correct 420 ms 46596 KB Output is correct
34 Correct 1782 ms 47844 KB Output is correct
35 Correct 1218 ms 33688 KB Output is correct
36 Correct 1038 ms 29264 KB Output is correct
37 Correct 301 ms 51160 KB Output is correct
38 Correct 4290 ms 50864 KB Output is correct