제출 #741299

#제출 시각아이디문제언어결과실행 시간메모리
741299Patrick열대 식물원 (Tropical Garden) (IOI11_garden)C++17
69 / 100
5027 ms78364 KiB
#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); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...