답안 #511317

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
511317 2022-01-15T14:19:53 Z tabr 열대 식물원 (Tropical Garden) (IOI11_garden) C++17
69 / 100
5000 ms 39656 KB
#include <bits/stdc++.h>
using namespace std;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

#ifdef tabr
void answer(int n) {
    cout << n << '\n';
}
#else
#include "garden.h"
#include "gardenlib.h"
#endif

void count_routes(int n, int m, int p, int r[][2], int q, int k[]) {
    int g[150000][2] = {};
    for (int i = 0; i < n; i++) {
        g[i][0] = g[i][1] = -1;
    }
    for (int i = 0; i < m; i++) {
        int x = r[i][0];
        int y = r[i][1];
        if (g[x][0] == -1) {
            g[x][0] = y;
        } else if (g[x][1] == -1) {
            g[x][1] = y;
        }
        if (g[y][0] == -1) {
            g[y][0] = x;
        } else if (g[y][1] == -1) {
            g[y][1] = x;
        }
    }
    int nxt[30][300000] = {};
    for (int i = 0; i < n; i++) {
        nxt[0][i] = g[i][0];
        nxt[0][i + n] = (g[i][1] == -1 ? g[i][0] : g[i][1]);
        if (g[nxt[0][i]][0] == i) {
            nxt[0][i] += n;
        }
        if (g[nxt[0][i + n]][0] == i) {
            nxt[0][i + n] += n;
        }
    }
    for (int i = 1; i < 30; i++) {
        for (int j = 0; j < 2 * n; j++) {
            nxt[i][j] = nxt[i - 1][nxt[i - 1][j]];
        }
    }
    for (int i = 0; i < q; i++) {
        int ans = 0;
        for (int j = 0; j < n; j++) {
            int v = j;
            for (int l = 29; l >= 0; l--) {
                if (k[i] & (1 << l)) {
                    v = nxt[l][v];
                }
            }
            if (v % n == p) {
                ans++;
            }
            debug(v, j);
        }
        answer(ans);
    }
}

#ifdef tabr
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, p, q;
    cin >> n >> m >> p >> q;
    int r[100][2];
    int k[100];
    for (int i = 0; i < m; i++) {
        cin >> r[i][0] >> r[i][1];
    }
    for (int i = 0; i < q; i++) {
        cin >> k[i];
    }
    count_routes(n, m, p, r, q, k);
    return 0;
}
#endif
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 36684 KB Output is correct
2 Correct 17 ms 36656 KB Output is correct
3 Correct 17 ms 36640 KB Output is correct
4 Correct 17 ms 36652 KB Output is correct
5 Correct 18 ms 36616 KB Output is correct
6 Correct 19 ms 36660 KB Output is correct
7 Correct 18 ms 36684 KB Output is correct
8 Correct 18 ms 36684 KB Output is correct
9 Correct 19 ms 36796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 36684 KB Output is correct
2 Correct 17 ms 36656 KB Output is correct
3 Correct 17 ms 36640 KB Output is correct
4 Correct 17 ms 36652 KB Output is correct
5 Correct 18 ms 36616 KB Output is correct
6 Correct 19 ms 36660 KB Output is correct
7 Correct 18 ms 36684 KB Output is correct
8 Correct 18 ms 36684 KB Output is correct
9 Correct 19 ms 36796 KB Output is correct
10 Correct 17 ms 36648 KB Output is correct
11 Correct 24 ms 37068 KB Output is correct
12 Correct 35 ms 37552 KB Output is correct
13 Correct 41 ms 38292 KB Output is correct
14 Correct 55 ms 39404 KB Output is correct
15 Correct 61 ms 39472 KB Output is correct
16 Correct 52 ms 39296 KB Output is correct
17 Correct 50 ms 39280 KB Output is correct
18 Correct 30 ms 37676 KB Output is correct
19 Correct 54 ms 39456 KB Output is correct
20 Correct 62 ms 39656 KB Output is correct
21 Correct 50 ms 39364 KB Output is correct
22 Correct 52 ms 39200 KB Output is correct
23 Correct 62 ms 39516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 36684 KB Output is correct
2 Correct 17 ms 36656 KB Output is correct
3 Correct 17 ms 36640 KB Output is correct
4 Correct 17 ms 36652 KB Output is correct
5 Correct 18 ms 36616 KB Output is correct
6 Correct 19 ms 36660 KB Output is correct
7 Correct 18 ms 36684 KB Output is correct
8 Correct 18 ms 36684 KB Output is correct
9 Correct 19 ms 36796 KB Output is correct
10 Correct 17 ms 36648 KB Output is correct
11 Correct 24 ms 37068 KB Output is correct
12 Correct 35 ms 37552 KB Output is correct
13 Correct 41 ms 38292 KB Output is correct
14 Correct 55 ms 39404 KB Output is correct
15 Correct 61 ms 39472 KB Output is correct
16 Correct 52 ms 39296 KB Output is correct
17 Correct 50 ms 39280 KB Output is correct
18 Correct 30 ms 37676 KB Output is correct
19 Correct 54 ms 39456 KB Output is correct
20 Correct 62 ms 39656 KB Output is correct
21 Correct 50 ms 39364 KB Output is correct
22 Correct 52 ms 39200 KB Output is correct
23 Correct 62 ms 39516 KB Output is correct
24 Correct 25 ms 36676 KB Output is correct
25 Correct 2328 ms 37128 KB Output is correct
26 Correct 3852 ms 37700 KB Output is correct
27 Execution timed out 5014 ms 38360 KB Time limit exceeded
28 Halted 0 ms 0 KB -