Submission #741281

# Submission time Handle Problem Language Result Execution time Memory
741281 2023-05-14T01:01:07 Z Patrick Tropical Garden (IOI11_garden) C++17
0 / 100
1 ms 596 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];
                }
            }
            {
                auto [at, c] = next2[l - 1][i];
                if (c) {
                    next2[l][i] = next1[l - 1][at];
                } else {
                    next2[l][i] = next2[l - 1][at];
                }
            }
        }
    }

    for (int i = 0; i < Q; i++) {
        int K = G[i], ans = 0;
        for (int j = 0; j < N; j++) {
            int cur = j, c = true;
            for (int k = 0; k <= 30; k++) {
                if (K & (1 << k)) {
                    if (c) {
                        cur = next1[k][cur].first;
                        c = next1[k][cur].second;
                    } else {
                        cur = next2[k][cur].first;
                        c = next2[k][cur].second;
                    }
                }
            }
            // cout << "start " << j << " steps " << K << " dest " << cur <<
            // "\n";
            if (cur == P) {
                ans++;
            }
        }
        answer(ans);
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 596 KB Output isn't correct
2 Halted 0 ms 0 KB -