#include <bits/stdc++.h>
using namespace std;
#include "garden.h"
#include "gardenlib.h"
const int LIM = 1.5e5, INF = 2e9;
int n, cnt[LIM], c, d[2][LIM*2], p, r[2] = {INF, INF};
vector<int> g[LIM*2];
void dfs(int u, int dist){
if(u == p+c*n && dist) return void(r[c] = dist);
if(u < n) ++d[c][dist];
for(int v : g[u]) dfs(v, dist + 1);
}
void count_routes(int N, int M, int P, int R[][2], int Q, int G[]){
n = N, p = P;
for(int i=0; i<M; ++i){
for(int j=0; j<2; ++j){
int u = R[i][j], v = R[i][!j];
if(cnt[u] == 0) g[v + (!cnt[v])*n].push_back(u);
if(cnt[u] == 1) g[v + (!cnt[v])*n].push_back(u+n);
}
for(int j=0; j<2; ++j) ++cnt[R[i][j]];
}
for(int u=0; u<n; ++u) if(cnt[u] < 2){
for(int v : g[u+n]) g[u].push_back(v);
g[u+n].clear();
}
for(c=0; c<2; ++c) dfs(p+c*n, 0);
for(int j=0; j<2; ++j){
for(int i=r[j]; i<n+n; ++i){
d[j][i] += d[j][i-r[j]];
}
}
n = 2*n - 1;
int l[2];
for(int j=0; j<2; ++j) if(r[j] < n){
l[j] = r[j] * (n / r[j]);
while(l[j] <= n) l[j] += r[j];
}
for(int i=0; i<Q; ++i){
int res = 0;
for(int j=0; j<2; ++j){
if(G[i] > n && r[j] <= n){
int x = l[j] + (G[i] % r[j]);
while(x > n) x -= r[j];
res += d[j][x];
}
if(G[i] <= n){
res += d[j][G[i]];
}
}
answer(res);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7372 KB |
Output is correct |
2 |
Correct |
5 ms |
7372 KB |
Output is correct |
3 |
Correct |
5 ms |
7372 KB |
Output is correct |
4 |
Correct |
5 ms |
7372 KB |
Output is correct |
5 |
Correct |
5 ms |
7372 KB |
Output is correct |
6 |
Correct |
6 ms |
7500 KB |
Output is correct |
7 |
Correct |
6 ms |
7372 KB |
Output is correct |
8 |
Correct |
6 ms |
7372 KB |
Output is correct |
9 |
Correct |
7 ms |
7500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7372 KB |
Output is correct |
2 |
Correct |
5 ms |
7372 KB |
Output is correct |
3 |
Correct |
5 ms |
7372 KB |
Output is correct |
4 |
Correct |
5 ms |
7372 KB |
Output is correct |
5 |
Correct |
5 ms |
7372 KB |
Output is correct |
6 |
Correct |
6 ms |
7500 KB |
Output is correct |
7 |
Correct |
6 ms |
7372 KB |
Output is correct |
8 |
Correct |
6 ms |
7372 KB |
Output is correct |
9 |
Correct |
7 ms |
7500 KB |
Output is correct |
10 |
Correct |
5 ms |
7372 KB |
Output is correct |
11 |
Correct |
15 ms |
8908 KB |
Output is correct |
12 |
Correct |
24 ms |
9984 KB |
Output is correct |
13 |
Correct |
67 ms |
19604 KB |
Output is correct |
14 |
Correct |
83 ms |
16452 KB |
Output is correct |
15 |
Correct |
137 ms |
16564 KB |
Output is correct |
16 |
Correct |
88 ms |
13868 KB |
Output is correct |
17 |
Correct |
66 ms |
12228 KB |
Output is correct |
18 |
Correct |
26 ms |
9292 KB |
Output is correct |
19 |
Correct |
85 ms |
16356 KB |
Output is correct |
20 |
Correct |
128 ms |
16536 KB |
Output is correct |
21 |
Correct |
94 ms |
13016 KB |
Output is correct |
22 |
Correct |
69 ms |
12852 KB |
Output is correct |
23 |
Correct |
79 ms |
17340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7372 KB |
Output is correct |
2 |
Correct |
5 ms |
7372 KB |
Output is correct |
3 |
Correct |
5 ms |
7372 KB |
Output is correct |
4 |
Correct |
5 ms |
7372 KB |
Output is correct |
5 |
Correct |
5 ms |
7372 KB |
Output is correct |
6 |
Correct |
6 ms |
7500 KB |
Output is correct |
7 |
Correct |
6 ms |
7372 KB |
Output is correct |
8 |
Correct |
6 ms |
7372 KB |
Output is correct |
9 |
Correct |
7 ms |
7500 KB |
Output is correct |
10 |
Correct |
5 ms |
7372 KB |
Output is correct |
11 |
Correct |
15 ms |
8908 KB |
Output is correct |
12 |
Correct |
24 ms |
9984 KB |
Output is correct |
13 |
Correct |
67 ms |
19604 KB |
Output is correct |
14 |
Correct |
83 ms |
16452 KB |
Output is correct |
15 |
Correct |
137 ms |
16564 KB |
Output is correct |
16 |
Correct |
88 ms |
13868 KB |
Output is correct |
17 |
Correct |
66 ms |
12228 KB |
Output is correct |
18 |
Correct |
26 ms |
9292 KB |
Output is correct |
19 |
Correct |
85 ms |
16356 KB |
Output is correct |
20 |
Correct |
128 ms |
16536 KB |
Output is correct |
21 |
Correct |
94 ms |
13016 KB |
Output is correct |
22 |
Correct |
69 ms |
12852 KB |
Output is correct |
23 |
Correct |
79 ms |
17340 KB |
Output is correct |
24 |
Correct |
7 ms |
7372 KB |
Output is correct |
25 |
Correct |
15 ms |
9032 KB |
Output is correct |
26 |
Correct |
31 ms |
9932 KB |
Output is correct |
27 |
Correct |
46 ms |
19652 KB |
Output is correct |
28 |
Correct |
77 ms |
16476 KB |
Output is correct |
29 |
Correct |
98 ms |
16504 KB |
Output is correct |
30 |
Correct |
72 ms |
13800 KB |
Output is correct |
31 |
Correct |
73 ms |
12228 KB |
Output is correct |
32 |
Correct |
35 ms |
9276 KB |
Output is correct |
33 |
Correct |
104 ms |
16444 KB |
Output is correct |
34 |
Correct |
109 ms |
16492 KB |
Output is correct |
35 |
Correct |
88 ms |
12980 KB |
Output is correct |
36 |
Correct |
75 ms |
12196 KB |
Output is correct |
37 |
Correct |
79 ms |
17356 KB |
Output is correct |
38 |
Correct |
160 ms |
25540 KB |
Output is correct |