#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
int n,m,k,q;
vector<int> al[150005];
int v[300005];
int par[30][300005];
int nxt[6][32][300005];
void count_routes(int N, int M, int P, int R[][2], int Q, int g[]){
n=N,m=M,k=P,q=Q;
rep(x,0,m){
al[R[x][0]].push_back(x*2);
al[R[x][1]].push_back(x*2+1);
v[x*2]=R[x][1];
v[x*2+1]=R[x][0];
}
rep(x,0,m*2){
if (sz(al[v[x]])==1 || (al[v[x]][0]>>1)!=(x>>1)) par[0][x]=al[v[x]][0];
else par[0][x]=al[v[x]][1];
}
//rep(x,0,m*2) cout<<nxt[0][x]<<endl;
rep(layer,0,29){
rep(x,0,m*2){
par[layer+1][x]=par[layer][par[layer][x]];
}
}
rep(layer,0,6){
rep(bm,0,32){
rep(x,0,m*2){
int curr=x;
rep(bit,0,5) if (bm&(1<<bit)){
curr=par[layer*5+bit][curr];
}
nxt[layer][bm][x]=curr;
}
}
}
rep(x,0,q){
int ans=0;
g[x]--;
rep(y,0,n){
int curr=al[y][0];
int bm=g[x];
rep(layer,0,6){
curr=nxt[layer][bm&31][curr];
bm>>=5;
}
if (v[curr]==k) ans++;
}
answer(ans);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
6656 KB |
Output is correct |
2 |
Correct |
8 ms |
6912 KB |
Output is correct |
3 |
Correct |
9 ms |
7168 KB |
Output is correct |
4 |
Correct |
4 ms |
5376 KB |
Output is correct |
5 |
Correct |
4 ms |
5376 KB |
Output is correct |
6 |
Correct |
13 ms |
8960 KB |
Output is correct |
7 |
Correct |
6 ms |
5632 KB |
Output is correct |
8 |
Correct |
8 ms |
7168 KB |
Output is correct |
9 |
Correct |
41 ms |
19456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
6656 KB |
Output is correct |
2 |
Correct |
8 ms |
6912 KB |
Output is correct |
3 |
Correct |
9 ms |
7168 KB |
Output is correct |
4 |
Correct |
4 ms |
5376 KB |
Output is correct |
5 |
Correct |
4 ms |
5376 KB |
Output is correct |
6 |
Correct |
13 ms |
8960 KB |
Output is correct |
7 |
Correct |
6 ms |
5632 KB |
Output is correct |
8 |
Correct |
8 ms |
7168 KB |
Output is correct |
9 |
Correct |
41 ms |
19456 KB |
Output is correct |
10 |
Correct |
4 ms |
5376 KB |
Output is correct |
11 |
Correct |
112 ms |
45304 KB |
Output is correct |
12 |
Correct |
265 ms |
98424 KB |
Output is correct |
13 |
Correct |
376 ms |
157176 KB |
Output is correct |
14 |
Correct |
710 ms |
259192 KB |
Output is correct |
15 |
Runtime error |
711 ms |
262144 KB |
Execution killed with signal 9 |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
6656 KB |
Output is correct |
2 |
Correct |
8 ms |
6912 KB |
Output is correct |
3 |
Correct |
9 ms |
7168 KB |
Output is correct |
4 |
Correct |
4 ms |
5376 KB |
Output is correct |
5 |
Correct |
4 ms |
5376 KB |
Output is correct |
6 |
Correct |
13 ms |
8960 KB |
Output is correct |
7 |
Correct |
6 ms |
5632 KB |
Output is correct |
8 |
Correct |
8 ms |
7168 KB |
Output is correct |
9 |
Correct |
41 ms |
19456 KB |
Output is correct |
10 |
Correct |
4 ms |
5376 KB |
Output is correct |
11 |
Correct |
112 ms |
45304 KB |
Output is correct |
12 |
Correct |
265 ms |
98424 KB |
Output is correct |
13 |
Correct |
376 ms |
157176 KB |
Output is correct |
14 |
Correct |
710 ms |
259192 KB |
Output is correct |
15 |
Runtime error |
711 ms |
262144 KB |
Execution killed with signal 9 |
16 |
Halted |
0 ms |
0 KB |
- |