답안 #241178

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
241178 2020-06-23T08:07:54 Z kshitij_sodani 열대 식물원 (Tropical Garden) (IOI11_garden) C++17
100 / 100
3221 ms 177200 KB
#include <bits/stdc++.h>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define pb push_back
#define a first 
#define b second
//#include "garden.h"

void answer(int x);

//#define endl '\n'
vector<int> adj[3000001];
vector<int> adj2[3000001];
int dist[300001];
int cyc;
vector<pair<int,int>> mi[150001];
void dfs(int no,int levv=0){
	dist[no]=levv;
	for(auto j:adj2[no]){
		if(dist[j]!=-1){
			cyc=levv+1;
		}
		else{
			dfs(j,levv+1);
		}
	}
}
void count_routes(int n,int m,int p,int r[][2],int q,int arr[]){
	
	for(int i=0;i<m;i++){
		mi[r[i][0]].pb({i,r[i][1]});
		mi[r[i][1]].pb({i,r[i][0]});
	}
	for(int i=0;i<n;i++){
		sort(mi[i].begin(),mi[i].end());
	}
	for(int i=0;i<n;i++){
		if(mi[mi[i][0].b][0].a==mi[i][0].a){
			adj[i].pb(n+mi[i][0].b);
		}
		else{
			adj[i].pb(mi[i][0].b);
		}
		int ind=0;
		if(mi[i].size()>1){
			ind=1;
		}
	//	cout<<i<<":"<<ind<<endl;
		if(mi[mi[i][ind].b][0].a==mi[i][ind].a){
			adj[n+i].pb(n+mi[i][ind].b);
		}
		else{
			adj[n+i].pb(mi[i][ind].b);
		}
	}
	for(int i=0;i<2*n;i++){
		for(auto j:adj[i]){
			adj2[j].pb(i);
	//		cout<<i<<","<<j<<endl;
		}
	}
	int ans[q];
	for(int i=0;i<q;i++){
		ans[i]=0;
	}
	for(int ii=0;ii<2;ii++){
		int aa;
		if(ii==0){
			aa=p;
		}
		else{
			aa=p+n;
		}
		for(int i=0;i<2*n;i++){
			dist[i]=-1;
		}
		cyc=-1;
		dfs(aa);
	/*	for(int i=0;i<2*n;i++){
			cout<<dist[i]<<",";
		}
		cout<<endl;
		cout<<cyc<<endl;*/

		for(int j=0;j<q;j++){
			for(int i=0;i<n;i++){
				if(dist[i]==-1){
					continue;
				}
				if(cyc==-1){
					if(dist[i]==arr[j]){
						ans[j]+=1;
					}
				}
				else{
					if(dist[i]==arr[j]){
						ans[j]+=1;
					}
					else if(dist[i]<arr[j]){
						if((arr[j]-dist[i])%cyc==0){
							ans[j]+=1;
						}
					}
				}
			}
		}
	//	cout<<ans[0]<<endl;
	}
	for(int i=0;i<q;i++){
		answer(ans[i]);
	}



}
/*int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);






	return 0;
}*/
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 144888 KB Output is correct
2 Correct 85 ms 144760 KB Output is correct
3 Correct 91 ms 144888 KB Output is correct
4 Correct 86 ms 144740 KB Output is correct
5 Correct 82 ms 144760 KB Output is correct
6 Correct 86 ms 145016 KB Output is correct
7 Correct 84 ms 144760 KB Output is correct
8 Correct 85 ms 145016 KB Output is correct
9 Correct 87 ms 145196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 144888 KB Output is correct
2 Correct 85 ms 144760 KB Output is correct
3 Correct 91 ms 144888 KB Output is correct
4 Correct 86 ms 144740 KB Output is correct
5 Correct 82 ms 144760 KB Output is correct
6 Correct 86 ms 145016 KB Output is correct
7 Correct 84 ms 144760 KB Output is correct
8 Correct 85 ms 145016 KB Output is correct
9 Correct 87 ms 145196 KB Output is correct
10 Correct 83 ms 144760 KB Output is correct
11 Correct 98 ms 148472 KB Output is correct
12 Correct 118 ms 151544 KB Output is correct
13 Correct 137 ms 165880 KB Output is correct
14 Correct 222 ms 166776 KB Output is correct
15 Correct 255 ms 167176 KB Output is correct
16 Correct 204 ms 161528 KB Output is correct
17 Correct 197 ms 159608 KB Output is correct
18 Correct 129 ms 151416 KB Output is correct
19 Correct 261 ms 166788 KB Output is correct
20 Correct 285 ms 167160 KB Output is correct
21 Correct 228 ms 161528 KB Output is correct
22 Correct 190 ms 159584 KB Output is correct
23 Correct 286 ms 168920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 144888 KB Output is correct
2 Correct 85 ms 144760 KB Output is correct
3 Correct 91 ms 144888 KB Output is correct
4 Correct 86 ms 144740 KB Output is correct
5 Correct 82 ms 144760 KB Output is correct
6 Correct 86 ms 145016 KB Output is correct
7 Correct 84 ms 144760 KB Output is correct
8 Correct 85 ms 145016 KB Output is correct
9 Correct 87 ms 145196 KB Output is correct
10 Correct 83 ms 144760 KB Output is correct
11 Correct 98 ms 148472 KB Output is correct
12 Correct 118 ms 151544 KB Output is correct
13 Correct 137 ms 165880 KB Output is correct
14 Correct 222 ms 166776 KB Output is correct
15 Correct 255 ms 167176 KB Output is correct
16 Correct 204 ms 161528 KB Output is correct
17 Correct 197 ms 159608 KB Output is correct
18 Correct 129 ms 151416 KB Output is correct
19 Correct 261 ms 166788 KB Output is correct
20 Correct 285 ms 167160 KB Output is correct
21 Correct 228 ms 161528 KB Output is correct
22 Correct 190 ms 159584 KB Output is correct
23 Correct 286 ms 168920 KB Output is correct
24 Correct 94 ms 144888 KB Output is correct
25 Correct 176 ms 148600 KB Output is correct
26 Correct 205 ms 151416 KB Output is correct
27 Correct 2619 ms 165884 KB Output is correct
28 Correct 1074 ms 166776 KB Output is correct
29 Correct 3221 ms 167288 KB Output is correct
30 Correct 1825 ms 161656 KB Output is correct
31 Correct 1933 ms 159752 KB Output is correct
32 Correct 209 ms 151544 KB Output is correct
33 Correct 1055 ms 166952 KB Output is correct
34 Correct 3163 ms 167288 KB Output is correct
35 Correct 1916 ms 161504 KB Output is correct
36 Correct 2412 ms 159736 KB Output is correct
37 Correct 825 ms 168952 KB Output is correct
38 Correct 2988 ms 177200 KB Output is correct