Submission #551248

# Submission time Handle Problem Language Result Execution time Memory
551248 2022-04-20T06:45:28 Z Koosha_mv Tropical Garden (IOI11_garden) C++14
100 / 100
2492 ms 65332 KB
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
#include "garden.h"
#include "gardenlib.h"

const int N=1e6+99,inf=1e9+99;

int n,m,s,a[N][2],b[N],p[N],vis[N],dist0[N],dist1[N];
vector<int> g[N],adj[N];

void dfs0(int u){
	dist0[u]=inf;
	vis[u]=1;
	if(u==(s<<1)){
		dist0[u]=0;
		return ;
	}
	if(vis[p[u]]==0) dfs0(p[u]);
	dist0[u]=dist0[p[u]]+1;
}
void dfs1(int u){
	dist1[u]=inf;
	vis[u]=1;
	if(u==(s<<1|1)){
		dist1[u]=0;
		return ;
	}
	if(vis[p[u]]==0) dfs1(p[u]);
	dist1[u]=dist1[p[u]]+1;
}
void count_routes(int _n, int _m, int _s, int R[][2], int Q, int G[]){
	n=_n,m=_m,s=_s;
	f(i,0,m){
		int u=R[i][0],v=R[i][1];
		if(g[u].size()<2) adj[u].pb(v);
		if(g[v].size()<2) adj[v].pb(u);
	}	
	f(i,0,n){
		p[i<<1]=(adj[i][0]<<1)+(adj[adj[i][0]][0]==i ? 1 : 0);
		if(adj[i].size()<2) p[i<<1|1]=p[i<<1];
		else{
			p[i<<1|1]=(adj[i][1]<<1)+(adj[adj[i][1]][0]==i ? 1 : 0);
		}
	}
	f(i,0,n<<1) if(!vis[i]) dfs0(i);
	fill(vis,vis+N,0);
	f(i,0,n<<1) if(!vis[i]) dfs1(i);
	
	int u,len0=0,len1=0;
	
	fill(vis,vis+N,0);
	u=s<<1;
	while(1){
		vis[u]=1;
		len0++;
		if(vis[p[u]]) break;
		u=p[u];
	}
	if(p[u]!=(s<<1)) len0=inf;
	
	fill(vis,vis+N,0);
	u=s<<1|1;
	while(1){
		vis[u]=1;
		len1++;
		if(vis[p[u]]) break;
		u=p[u];
	}
	if(p[u]!=(s<<1|1)) len1=inf;
	f(i,0,Q){
		int k=G[i],res=0;
		f(i,0,n){
			//if(i==5){
			//	eror(dist0[i<<1]);
			//}
			if((dist0[i<<1]<=k && (k-dist0[i<<1])%len0==0) || (dist1[i<<1]<=k && (k-dist1[i<<1])%len1==0)){
				//eror(i);
				res++;
			}
		}
		//cout<<"res - "<<res<<endl;;
		answer(res);
	}
}


/*
int32_t main(){
	ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n,m,s,q;
	cin>>n>>m>>s>>q;
	f(i,0,m) cin>>a[i][0]>>a[i][1];
	f(i,0,q) cin>>b[i];
	count_routes(n,m,s,a,q,b);
}
*/
/*
6 6 0 1
1 2
0 1
0 3
3 4
4 5
1 5
3
*/
# Verdict Execution time Memory Grader output
1 Correct 24 ms 51244 KB Output is correct
2 Correct 24 ms 51228 KB Output is correct
3 Correct 27 ms 51232 KB Output is correct
4 Correct 23 ms 51132 KB Output is correct
5 Correct 23 ms 51160 KB Output is correct
6 Correct 26 ms 51380 KB Output is correct
7 Correct 25 ms 51248 KB Output is correct
8 Correct 25 ms 51284 KB Output is correct
9 Correct 26 ms 51476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 51244 KB Output is correct
2 Correct 24 ms 51228 KB Output is correct
3 Correct 27 ms 51232 KB Output is correct
4 Correct 23 ms 51132 KB Output is correct
5 Correct 23 ms 51160 KB Output is correct
6 Correct 26 ms 51380 KB Output is correct
7 Correct 25 ms 51248 KB Output is correct
8 Correct 25 ms 51284 KB Output is correct
9 Correct 26 ms 51476 KB Output is correct
10 Correct 25 ms 51284 KB Output is correct
11 Correct 32 ms 52728 KB Output is correct
12 Correct 43 ms 54020 KB Output is correct
13 Correct 53 ms 61820 KB Output is correct
14 Correct 83 ms 59868 KB Output is correct
15 Correct 90 ms 59996 KB Output is correct
16 Correct 79 ms 57856 KB Output is correct
17 Correct 82 ms 57164 KB Output is correct
18 Correct 42 ms 53768 KB Output is correct
19 Correct 83 ms 59864 KB Output is correct
20 Correct 88 ms 60088 KB Output is correct
21 Correct 77 ms 57792 KB Output is correct
22 Correct 76 ms 57120 KB Output is correct
23 Correct 88 ms 60816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 51244 KB Output is correct
2 Correct 24 ms 51228 KB Output is correct
3 Correct 27 ms 51232 KB Output is correct
4 Correct 23 ms 51132 KB Output is correct
5 Correct 23 ms 51160 KB Output is correct
6 Correct 26 ms 51380 KB Output is correct
7 Correct 25 ms 51248 KB Output is correct
8 Correct 25 ms 51284 KB Output is correct
9 Correct 26 ms 51476 KB Output is correct
10 Correct 25 ms 51284 KB Output is correct
11 Correct 32 ms 52728 KB Output is correct
12 Correct 43 ms 54020 KB Output is correct
13 Correct 53 ms 61820 KB Output is correct
14 Correct 83 ms 59868 KB Output is correct
15 Correct 90 ms 59996 KB Output is correct
16 Correct 79 ms 57856 KB Output is correct
17 Correct 82 ms 57164 KB Output is correct
18 Correct 42 ms 53768 KB Output is correct
19 Correct 83 ms 59864 KB Output is correct
20 Correct 88 ms 60088 KB Output is correct
21 Correct 77 ms 57792 KB Output is correct
22 Correct 76 ms 57120 KB Output is correct
23 Correct 88 ms 60816 KB Output is correct
24 Correct 30 ms 51200 KB Output is correct
25 Correct 106 ms 52692 KB Output is correct
26 Correct 133 ms 53976 KB Output is correct
27 Correct 2237 ms 61896 KB Output is correct
28 Correct 822 ms 60060 KB Output is correct
29 Correct 2492 ms 60112 KB Output is correct
30 Correct 1405 ms 57912 KB Output is correct
31 Correct 1448 ms 57192 KB Output is correct
32 Correct 145 ms 53972 KB Output is correct
33 Correct 819 ms 60028 KB Output is correct
34 Correct 2484 ms 60100 KB Output is correct
35 Correct 1498 ms 57888 KB Output is correct
36 Correct 1700 ms 57228 KB Output is correct
37 Correct 618 ms 61032 KB Output is correct
38 Correct 1939 ms 65332 KB Output is correct