Submission #1163018

#TimeUsernameProblemLanguageResultExecution timeMemory
1163018HappyCapybaraTropical Garden (IOI11_garden)C++20
69 / 100
5094 ms47356 KiB
#include "garden.h" #include "gardenlib.h" #include<bits/stdc++.h> using namespace std; void count_routes(int N, int M, int P, int R[][2], int Q, int G[]){ vector<vector<int>> mb(2, vector<int>(N, -1)); for (int i=0; i<M; i++){ if (mb[0][R[i][0]] == -1) mb[0][R[i][0]] = i; else if (mb[1][R[i][0]] == -1) mb[1][R[i][0]] = i; if (mb[0][R[i][1]] == -1) mb[0][R[i][1]] = i; else if (mb[1][R[i][1]] == -1) mb[1][R[i][1]] = i; } for (int i=0; i<N; i++){ if (mb[1][i] == -1) mb[1][i] = mb[0][i]; } vector<vector<int>> bl(2*N, vector<int>(30)); for (int i=0; i<2*N; i++){ int next = R[mb[i%2][i/2]][0]+R[mb[i%2][i/2]][1]-i/2; bl[i][0] = 2*next+(mb[i%2][i/2] == mb[0][next]); } for (int j=1; j<30; j++){ for (int i=0; i<2*N; i++) bl[i][j] = bl[bl[i][j-1]][j-1]; } for (int i=0; i<Q; i++){ int res = 0; for (int k=0; k<N; k++){ int cur = 2*k; for (int j=29; j>=0; j--){ if (G[i] & (1<<j)) cur = bl[cur][j]; } if (cur/2 == P) res++; } answer(res); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...