답안 #741299

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
741299 2023-05-14T01:35:09 Z Patrick 열대 식물원 (Tropical Garden) (IOI11_garden) C++17
69 / 100
5000 ms 78364 KB
#include "garden.h"

#include <iostream>
#include <vector>

#include "gardenlib.h"

using namespace std;

void count_routes(int N, int M, int P, int R[][2], int Q, int G[]) {
    vector<int> n1(N, -1), n2(N, -1);
    for (int i = M - 1; i >= 0; i--) {
        int u = R[i][0], v = R[i][1];
        n2[u] = n1[u];
        n1[u] = v;
        n2[v] = n1[v];
        n1[v] = u;
    }
    for (int i = 0; i < N; i++) {
        if (n2[i] == -1) n2[i] = n1[i];
    }

    vector<vector<pair<int, bool>>> next1(31, vector<pair<int, bool>>(N)),
        next2(31, vector<pair<int, bool>>(N));
    for (int i = 0; i < N; i++) {
        next1[0][i] = {n1[i], n1[n1[i]] != i};
        next2[0][i] = {n2[i], n1[n2[i]] != i};
    }
    for (int l = 1; l <= 30; l++) {
        for (int i = 0; i < N; i++) {
            {
                auto [at, c] = next1[l - 1][i];
                if (c) {
                    next1[l][i] = next1[l - 1][at];
                } else {
                    next1[l][i] = next2[l - 1][at];
                }
                // cout << "n " << i << " 1 " << (1 << l) << " -> "
                // << next1[l][i].first << " " << next1[l][i].second << "\n";
            }
            {
                auto [at, c] = next2[l - 1][i];
                if (c) {
                    next2[l][i] = next1[l - 1][at];
                } else {
                    next2[l][i] = next2[l - 1][at];
                }
                // cout << "n " << i << " 0 " << (1 << l) << " -> "
                //      << next2[l][i].first << " " << next2[l][i].second <<
                //      "\n";
            }
        }
    }

    for (int i = 0; i < Q; i++) {
        int K = G[i], ans = 0;
        for (int j = 0; j < N; j++) {
            // cout << "try " << j << " " << K << " \n";
            int cur = j, c = true;
            for (int k = 0; k <= 30; k++) {
                if (K & (1 << k)) {
                    // cout << "step " << cur << " " << c << " to ";
                    if (c) {
                        auto [cur1, c1] = next1[k][cur];
                        cur = cur1;
                        c = c1;
                    } else {
                        auto [cur1, c1] = next2[k][cur];
                        cur = cur1;
                        c = c1;
                    }
                    // cout << cur << " " << c << " in " << (1 << k) << "\n";
                }
            }
            // cout << "start " << j << " steps " << K << " dest " << cur <<
            // "\n";
            if (cur == P) {
                // cout << "ok " << j << " " << K << " \n";
                ans++;
            }
        }
        answer(ans);
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 664 KB Output is correct
2 Correct 1 ms 724 KB Output is correct
3 Correct 1 ms 820 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 852 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 3 ms 852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 664 KB Output is correct
2 Correct 1 ms 724 KB Output is correct
3 Correct 1 ms 820 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 852 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 3 ms 852 KB Output is correct
10 Correct 1 ms 308 KB Output is correct
11 Correct 12 ms 11940 KB Output is correct
12 Correct 23 ms 20112 KB Output is correct
13 Correct 42 ms 44720 KB Output is correct
14 Correct 86 ms 70664 KB Output is correct
15 Correct 82 ms 71584 KB Output is correct
16 Correct 63 ms 48680 KB Output is correct
17 Correct 66 ms 41308 KB Output is correct
18 Correct 25 ms 20092 KB Output is correct
19 Correct 84 ms 70764 KB Output is correct
20 Correct 85 ms 71564 KB Output is correct
21 Correct 56 ms 48796 KB Output is correct
22 Correct 66 ms 41320 KB Output is correct
23 Correct 81 ms 78364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 664 KB Output is correct
2 Correct 1 ms 724 KB Output is correct
3 Correct 1 ms 820 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 852 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 3 ms 852 KB Output is correct
10 Correct 1 ms 308 KB Output is correct
11 Correct 12 ms 11940 KB Output is correct
12 Correct 23 ms 20112 KB Output is correct
13 Correct 42 ms 44720 KB Output is correct
14 Correct 86 ms 70664 KB Output is correct
15 Correct 82 ms 71584 KB Output is correct
16 Correct 63 ms 48680 KB Output is correct
17 Correct 66 ms 41308 KB Output is correct
18 Correct 25 ms 20092 KB Output is correct
19 Correct 84 ms 70764 KB Output is correct
20 Correct 85 ms 71564 KB Output is correct
21 Correct 56 ms 48796 KB Output is correct
22 Correct 66 ms 41320 KB Output is correct
23 Correct 81 ms 78364 KB Output is correct
24 Correct 7 ms 340 KB Output is correct
25 Correct 2126 ms 12160 KB Output is correct
26 Correct 3916 ms 20204 KB Output is correct
27 Execution timed out 5027 ms 44748 KB Time limit exceeded
28 Halted 0 ms 0 KB -