#include "garden.h"
#include "gardenlib.h"
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define pb push_back
typedef int64_t lld;
typedef pair<int, int> pii;
vector<pii> to;
vector<int> arr, arr2, tmp1, tmp2;
void calc(int n, int b){
tmp2.resize(n); tmp1.resize(n);
iota(all(tmp1), 0); arr2 = arr;
do{
//for(auto i: tmp1)cout << i << " "; cout << endl;
//for(auto i: arr2)cout << i << " "; cout << endl;
if(b&1)
for(int i = 0; i < n; i++)tmp1[i] = arr2[tmp1[i]];
for(int i = 0; i < n; i++)tmp2[i] = arr2[arr2[i]];
arr2 = tmp2;
}while(b>>=1);
}
vector<int> ans1, ans2, gone;
void dfs(int i, int P, vector<int>& ans){
if(arr[i] == P){
ans[i] = 1;
return;
}
if(!gone[arr[i]]){
gone[arr[i]] = true;
dfs(arr[i], P, ans);
}
if(ans[arr[i]] != INT_MAX)ans[i] = ans[arr[i]]+1;
}
void count_routes(int N, int M, int P, int R[][2], int Q, int G[]) {
to.resize(N, {-1, -1}); arr.resize(2*N);
for(int i = 0; i < M; i++){
if(to[R[i][0]].ff == -1)to[R[i][0]].ff = R[i][1];
else if(to[R[i][0]].ss == -1)to[R[i][0]].ss = R[i][1];
if(to[R[i][1]].ff == -1)to[R[i][1]].ff = R[i][0];
else if(to[R[i][1]].ss == -1)to[R[i][1]].ss = R[i][0];
}
for(int i = 0; i < N; i++){
if(to[i].ss == -1)to[i].ss = to[i].ff;
arr[2*i] = 2*to[i].ff + (to[to[i].ff].ff == i);
arr[2*i+1] = 2*to[i].ss + (to[to[i].ss].ff == i);
}
//for(auto i: to)cout << i.ff << " " << i.ss << " "; cout << endl;
//for(auto i: arr)cout << i << " "; cout << endl;
ans1.resize(2*N, INT_MAX); ans2.resize(2*N, INT_MAX); gone.resize(2*N, 0);
for(int i = 0; i < 2*N; i++) if(!gone[i])dfs(i, 2*P, ans1);
fill(all(gone), 0);
for(int i = 0; i < 2*N; i++) if(!gone[i])dfs(i, 2*P+1, ans2);
//for(auto i: ans1)cout << i << " "; cout << endl;
//for(auto i: ans2)cout << i << " "; cout << endl;
int d1 = 0, d2 = 0; swap(ans1[2*P], d1); swap(ans2[2*P+1], d2);
for(int j=0; j<Q; j++){
//for(auto i: tmp1)cout << i << " "; cout << endl;
int ans = 0;
for(int i = 0; i < N; i++)
if(ans1[2*i] <= G[j] && (G[j] - ans1[2*i])%d1 == 0 || ans2[2*i] <= G[j] && (G[j] - ans2[2*i])%d2 == 0)ans++;
answer(ans);
}
}
Compilation message
garden.cpp: In function 'void count_routes(int, int, int, int (*)[2], int, int*)':
garden.cpp:69:28: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
69 | if(ans1[2*i] <= G[j] && (G[j] - ans1[2*i])%d1 == 0 || ans2[2*i] <= G[j] && (G[j] - ans2[2*i])%d2 == 0)ans++;
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
288 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
288 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
512 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
11 ms |
1664 KB |
Output is correct |
12 |
Correct |
23 ms |
2560 KB |
Output is correct |
13 |
Correct |
34 ms |
9848 KB |
Output is correct |
14 |
Correct |
71 ms |
6904 KB |
Output is correct |
15 |
Correct |
76 ms |
7032 KB |
Output is correct |
16 |
Correct |
55 ms |
5240 KB |
Output is correct |
17 |
Correct |
53 ms |
4472 KB |
Output is correct |
18 |
Correct |
20 ms |
2432 KB |
Output is correct |
19 |
Correct |
70 ms |
6932 KB |
Output is correct |
20 |
Correct |
64 ms |
7024 KB |
Output is correct |
21 |
Correct |
58 ms |
5112 KB |
Output is correct |
22 |
Correct |
55 ms |
4472 KB |
Output is correct |
23 |
Correct |
74 ms |
7672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
288 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
512 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
11 ms |
1664 KB |
Output is correct |
12 |
Correct |
23 ms |
2560 KB |
Output is correct |
13 |
Correct |
34 ms |
9848 KB |
Output is correct |
14 |
Correct |
71 ms |
6904 KB |
Output is correct |
15 |
Correct |
76 ms |
7032 KB |
Output is correct |
16 |
Correct |
55 ms |
5240 KB |
Output is correct |
17 |
Correct |
53 ms |
4472 KB |
Output is correct |
18 |
Correct |
20 ms |
2432 KB |
Output is correct |
19 |
Correct |
70 ms |
6932 KB |
Output is correct |
20 |
Correct |
64 ms |
7024 KB |
Output is correct |
21 |
Correct |
58 ms |
5112 KB |
Output is correct |
22 |
Correct |
55 ms |
4472 KB |
Output is correct |
23 |
Correct |
74 ms |
7672 KB |
Output is correct |
24 |
Correct |
3 ms |
388 KB |
Output is correct |
25 |
Correct |
95 ms |
1652 KB |
Output is correct |
26 |
Correct |
132 ms |
2560 KB |
Output is correct |
27 |
Correct |
2518 ms |
10752 KB |
Output is correct |
28 |
Correct |
990 ms |
8496 KB |
Output is correct |
29 |
Correct |
2873 ms |
8696 KB |
Output is correct |
30 |
Correct |
1620 ms |
6776 KB |
Output is correct |
31 |
Correct |
1683 ms |
6040 KB |
Output is correct |
32 |
Correct |
135 ms |
2808 KB |
Output is correct |
33 |
Correct |
969 ms |
8500 KB |
Output is correct |
34 |
Correct |
2829 ms |
8680 KB |
Output is correct |
35 |
Correct |
1720 ms |
6656 KB |
Output is correct |
36 |
Correct |
1939 ms |
6136 KB |
Output is correct |
37 |
Correct |
693 ms |
9464 KB |
Output is correct |
38 |
Correct |
2198 ms |
14136 KB |
Output is correct |