#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include "garden.h"
#include "gardenlib.h"
using namespace std;
typedef long long ll;
//#define int ll
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
vector<int> v[200010];
int p[30][300010];
int n;
int sol(int P,int k,int pos){
for(int i=0;i<30;i++){
if(k&(1<<i))pos=p[i][pos];
}
if(pos==P || pos==n+P)return 1;
return 0;
}
void count_routes(int N,int M,int P,int R[][2],int Q,int G[]){
n=N;
for(int i=0;i<M;i++){
if(v[R[i][0]].size()<2)v[R[i][0]].push_back(R[i][1]);
if(v[R[i][1]].size()<2)v[R[i][1]].push_back(R[i][0]);
}
for(int i=0;i<N;i++){
p[0][i]=v[i][0];
if(v[v[i][0]][0]==i)p[0][i]+=N;
}
for(int i=0;i<N;i++){
p[0][i+N]=v[i].back();
if(v[v[i].back()][0]==i)p[0][i+N]+=N;
}
for(int i=1;i<30;i++){
for(int j=0;j<2*N;j++){
p[i][j]=p[i-1][p[i-1][j]];
}
}
for(int i=0;i<Q;i++){
int tot=0;
for(int j=0;j<N;j++)tot+=sol(P,G[i],j);
answer(tot);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
5504 KB |
Output is correct |
2 |
Correct |
8 ms |
5504 KB |
Output is correct |
3 |
Correct |
8 ms |
5504 KB |
Output is correct |
4 |
Correct |
7 ms |
5248 KB |
Output is correct |
5 |
Correct |
8 ms |
5248 KB |
Output is correct |
6 |
Correct |
8 ms |
5504 KB |
Output is correct |
7 |
Correct |
7 ms |
5248 KB |
Output is correct |
8 |
Correct |
8 ms |
5504 KB |
Output is correct |
9 |
Correct |
10 ms |
5632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
5504 KB |
Output is correct |
2 |
Correct |
8 ms |
5504 KB |
Output is correct |
3 |
Correct |
8 ms |
5504 KB |
Output is correct |
4 |
Correct |
7 ms |
5248 KB |
Output is correct |
5 |
Correct |
8 ms |
5248 KB |
Output is correct |
6 |
Correct |
8 ms |
5504 KB |
Output is correct |
7 |
Correct |
7 ms |
5248 KB |
Output is correct |
8 |
Correct |
8 ms |
5504 KB |
Output is correct |
9 |
Correct |
10 ms |
5632 KB |
Output is correct |
10 |
Correct |
8 ms |
5248 KB |
Output is correct |
11 |
Correct |
19 ms |
11648 KB |
Output is correct |
12 |
Correct |
39 ms |
16224 KB |
Output is correct |
13 |
Correct |
52 ms |
29432 KB |
Output is correct |
14 |
Correct |
111 ms |
44036 KB |
Output is correct |
15 |
Correct |
92 ms |
44408 KB |
Output is correct |
16 |
Correct |
73 ms |
32120 KB |
Output is correct |
17 |
Correct |
78 ms |
28156 KB |
Output is correct |
18 |
Correct |
33 ms |
16128 KB |
Output is correct |
19 |
Correct |
92 ms |
43896 KB |
Output is correct |
20 |
Correct |
92 ms |
44412 KB |
Output is correct |
21 |
Correct |
76 ms |
32208 KB |
Output is correct |
22 |
Correct |
88 ms |
28280 KB |
Output is correct |
23 |
Correct |
102 ms |
47864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
5504 KB |
Output is correct |
2 |
Correct |
8 ms |
5504 KB |
Output is correct |
3 |
Correct |
8 ms |
5504 KB |
Output is correct |
4 |
Correct |
7 ms |
5248 KB |
Output is correct |
5 |
Correct |
8 ms |
5248 KB |
Output is correct |
6 |
Correct |
8 ms |
5504 KB |
Output is correct |
7 |
Correct |
7 ms |
5248 KB |
Output is correct |
8 |
Correct |
8 ms |
5504 KB |
Output is correct |
9 |
Correct |
10 ms |
5632 KB |
Output is correct |
10 |
Correct |
8 ms |
5248 KB |
Output is correct |
11 |
Correct |
19 ms |
11648 KB |
Output is correct |
12 |
Correct |
39 ms |
16224 KB |
Output is correct |
13 |
Correct |
52 ms |
29432 KB |
Output is correct |
14 |
Correct |
111 ms |
44036 KB |
Output is correct |
15 |
Correct |
92 ms |
44408 KB |
Output is correct |
16 |
Correct |
73 ms |
32120 KB |
Output is correct |
17 |
Correct |
78 ms |
28156 KB |
Output is correct |
18 |
Correct |
33 ms |
16128 KB |
Output is correct |
19 |
Correct |
92 ms |
43896 KB |
Output is correct |
20 |
Correct |
92 ms |
44412 KB |
Output is correct |
21 |
Correct |
76 ms |
32208 KB |
Output is correct |
22 |
Correct |
88 ms |
28280 KB |
Output is correct |
23 |
Correct |
102 ms |
47864 KB |
Output is correct |
24 |
Correct |
15 ms |
5248 KB |
Output is correct |
25 |
Correct |
2432 ms |
11696 KB |
Output is correct |
26 |
Correct |
4412 ms |
16376 KB |
Output is correct |
27 |
Execution timed out |
5068 ms |
29688 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |