Submission #279302

# Submission time Handle Problem Language Result Execution time Memory
279302 2020-08-22T05:35:46 Z TMJN Tropical Garden (IOI11_garden) C++17
100 / 100
2904 ms 24580 KB
#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
using namespace std;

pair<int,bool>d[150000][2];
int dis[150000][2],DIS[150000][2];
vector<pair<int,bool>>r[150000][2];


void count_routes(int N, int M, int P, int R[][2], int Q, int G[]){
	for(int i=0;i<N;i++){
		d[i][0]=d[i][1]={-1,0};
	}
	for(int i=0;i<M;i++){
		int p=R[i][0];
		int q=R[i][1];
		if(d[p][0].first==-1){
			d[p][0].first=q;
		}
		else if(d[p][1].first==-1){
			d[p][1].first=q;
		}
		swap(p,q);
		if(d[p][0].first==-1){
			d[p][0].first=q;
		}
		else if(d[p][1].first==-1){
			d[p][1].first=q;
		}
	}
	for(int i=0;i<N;i++){
		if(d[d[i][0].first][0].first==i){
			d[i][0].second=true;
		}
		if(d[i][1].first==-1){
			d[i][1].first=d[i][0].first;
		}
		if(d[d[i][1].first][0].first==i){
			d[i][1].second=true;
		}
		r[d[i][0].first][d[i][0].second].push_back({i,0});
		r[d[i][1].first][d[i][1].second].push_back({i,1});
	}
	queue<pair<int,bool>>q;
	q.push({P,0});
	q.push({-1,0});
	int dd=0;
	while(q.size()>=2){
		auto p=q.front();
		q.pop();
		if(p==pair<int,bool>{-1,0}){
			dd++;
			q.push({-1,0});
			continue;
		}
		if(dis[p.first][p.second])continue;
		dis[p.first][p.second]=dd;
		for(auto pp:r[p.first][p.second]){
			q.push(pp);
		}
	}
	queue<pair<int,bool>>qq;
	swap(q,qq);
	dd=0;
	q.push({P,1});
	q.push({-1,0});
	while(q.size()>=2){
		auto p=q.front();
		q.pop();
		if(p==pair<int,bool>{-1,0}){
			dd++;
			q.push({-1,0});
			continue;
		}
		if(DIS[p.first][p.second])continue;
		DIS[p.first][p.second]=dd;
		for(auto pp:r[p.first][p.second]){
			q.push(pp);
		}
	}
	for(int i=0;i<Q;i++){
		int c=0;
		for(int j=0;j<N;j++){
			if(dis[j][0]==G[i]||(dis[j][0]<G[i]&&dis[P][0]&&dis[j][0]&&(G[i]-dis[j][0])%dis[P][0]==0)||DIS[j][0]==G[i]||(DIS[j][0]<G[i]&&DIS[P][1]&&DIS[j][0]&&(G[i]-DIS[j][0])%DIS[P][1]==0)){
				c++;
			}
		}
		answer(c);
	}
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 7424 KB Output is correct
2 Correct 5 ms 7552 KB Output is correct
3 Correct 6 ms 7552 KB Output is correct
4 Correct 5 ms 7424 KB Output is correct
5 Correct 5 ms 7424 KB Output is correct
6 Correct 6 ms 7552 KB Output is correct
7 Correct 5 ms 7424 KB Output is correct
8 Correct 5 ms 7424 KB Output is correct
9 Correct 8 ms 7552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 7424 KB Output is correct
2 Correct 5 ms 7552 KB Output is correct
3 Correct 6 ms 7552 KB Output is correct
4 Correct 5 ms 7424 KB Output is correct
5 Correct 5 ms 7424 KB Output is correct
6 Correct 6 ms 7552 KB Output is correct
7 Correct 5 ms 7424 KB Output is correct
8 Correct 5 ms 7424 KB Output is correct
9 Correct 8 ms 7552 KB Output is correct
10 Correct 6 ms 7424 KB Output is correct
11 Correct 14 ms 9472 KB Output is correct
12 Correct 29 ms 10744 KB Output is correct
13 Correct 44 ms 17056 KB Output is correct
14 Correct 93 ms 18808 KB Output is correct
15 Correct 110 ms 20088 KB Output is correct
16 Correct 82 ms 15992 KB Output is correct
17 Correct 74 ms 15736 KB Output is correct
18 Correct 27 ms 10872 KB Output is correct
19 Correct 89 ms 19448 KB Output is correct
20 Correct 113 ms 20088 KB Output is correct
21 Correct 84 ms 15992 KB Output is correct
22 Correct 77 ms 15736 KB Output is correct
23 Correct 93 ms 19520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 7424 KB Output is correct
2 Correct 5 ms 7552 KB Output is correct
3 Correct 6 ms 7552 KB Output is correct
4 Correct 5 ms 7424 KB Output is correct
5 Correct 5 ms 7424 KB Output is correct
6 Correct 6 ms 7552 KB Output is correct
7 Correct 5 ms 7424 KB Output is correct
8 Correct 5 ms 7424 KB Output is correct
9 Correct 8 ms 7552 KB Output is correct
10 Correct 6 ms 7424 KB Output is correct
11 Correct 14 ms 9472 KB Output is correct
12 Correct 29 ms 10744 KB Output is correct
13 Correct 44 ms 17056 KB Output is correct
14 Correct 93 ms 18808 KB Output is correct
15 Correct 110 ms 20088 KB Output is correct
16 Correct 82 ms 15992 KB Output is correct
17 Correct 74 ms 15736 KB Output is correct
18 Correct 27 ms 10872 KB Output is correct
19 Correct 89 ms 19448 KB Output is correct
20 Correct 113 ms 20088 KB Output is correct
21 Correct 84 ms 15992 KB Output is correct
22 Correct 77 ms 15736 KB Output is correct
23 Correct 93 ms 19520 KB Output is correct
24 Correct 7 ms 7424 KB Output is correct
25 Correct 160 ms 9468 KB Output is correct
26 Correct 252 ms 10872 KB Output is correct
27 Correct 2545 ms 17248 KB Output is correct
28 Correct 1355 ms 19832 KB Output is correct
29 Correct 2904 ms 20144 KB Output is correct
30 Correct 1635 ms 16292 KB Output is correct
31 Correct 1648 ms 15864 KB Output is correct
32 Correct 213 ms 11000 KB Output is correct
33 Correct 1337 ms 19448 KB Output is correct
34 Correct 2893 ms 20216 KB Output is correct
35 Correct 1753 ms 16376 KB Output is correct
36 Correct 1655 ms 15868 KB Output is correct
37 Correct 1117 ms 19704 KB Output is correct
38 Correct 2314 ms 24580 KB Output is correct