Submission #519505

# Submission time Handle Problem Language Result Execution time Memory
519505 2022-01-26T13:03:36 Z AdamGS Tropical Garden (IOI11_garden) C++17
100 / 100
95 ms 19968 KB
#include "garden.h"
#include "gardenlib.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=3e5+7, INF=1e9+7;
int nxt[LIM], odl[LIM], ile[LIM][2], ans[LIM][2], cykl[2], n;
vector<int>V[LIM];
void solve(int x, int r) {
	cykl[r]=INF;
	rep(i, 2*n) odl[i]=INF;
	odl[x]=0;
	queue<int>q;
	q.push(x);
	while(!q.empty()) {
		int p=q.front(); q.pop();
		for(auto i : V[p]) if(odl[i]>odl[p]+1) {
			odl[i]=odl[p]+1;
			q.push(i);
		}
		for(auto i : V[p]) if(i==x) cykl[r]=odl[p]+1;
	}
	sort(odl, odl+n);
	int l=0;
	rep(i, LIM) {
		int s=l;
		while(s<n && odl[s]==i) {
			++ans[i][r];
			++s;
		}
		if(cykl[r]<INF) {
			ans[i][r]+=ile[i%cykl[r]][r];
		}
		while(l<n && odl[l]==i) {
			++ile[i%cykl[r]][r];
			++l;
		}
	}
}
void count_routes(int N, int M, int P, int R[][2], int Q, int G[]) {
	n=N;
	rep(i, 2*n) nxt[i]=-1;
	rep(i, M) {
		int p1=R[i][1], p2=R[i][0];
		if(nxt[R[i][1]]==-1) p1+=n;
		if(nxt[R[i][0]]==-1) p2+=n;
		if(nxt[R[i][0]]==-1) nxt[R[i][0]]=p1;
		else if(nxt[R[i][0]+n]==-1) nxt[R[i][0]+n]=p1;
		if(nxt[R[i][1]]==-1) nxt[R[i][1]]=p2;
		else if(nxt[R[i][1]+n]==-1) nxt[R[i][1]+n]=p2;
	}
	rep(i, n) if(nxt[i]!=-1 && nxt[n+i]==-1) nxt[n+i]=nxt[i];
	rep(i, 2*n) if(nxt[i]!=-1) V[nxt[i]].pb(i);
	solve(P, 0);
	solve(P+n, 1);
	rep(i, Q) {
		if(G[i]<LIM) answer(ans[G[i]][0]+ans[G[i]][1]);
		else {
			int x=0;
			if(cykl[0]<INF) x+=ile[G[i]%cykl[0]][0];
			if(cykl[1]<INF) x+=ile[G[i]%cykl[1]][1];
			answer(x);
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9768 KB Output is correct
2 Correct 9 ms 9792 KB Output is correct
3 Correct 10 ms 9792 KB Output is correct
4 Correct 7 ms 9668 KB Output is correct
5 Correct 7 ms 9676 KB Output is correct
6 Correct 10 ms 9804 KB Output is correct
7 Correct 9 ms 9652 KB Output is correct
8 Correct 9 ms 9792 KB Output is correct
9 Correct 12 ms 9804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9768 KB Output is correct
2 Correct 9 ms 9792 KB Output is correct
3 Correct 10 ms 9792 KB Output is correct
4 Correct 7 ms 9668 KB Output is correct
5 Correct 7 ms 9676 KB Output is correct
6 Correct 10 ms 9804 KB Output is correct
7 Correct 9 ms 9652 KB Output is correct
8 Correct 9 ms 9792 KB Output is correct
9 Correct 12 ms 9804 KB Output is correct
10 Correct 9 ms 9652 KB Output is correct
11 Correct 16 ms 11396 KB Output is correct
12 Correct 26 ms 12612 KB Output is correct
13 Correct 50 ms 18776 KB Output is correct
14 Correct 70 ms 19116 KB Output is correct
15 Correct 91 ms 19452 KB Output is correct
16 Correct 72 ms 17068 KB Output is correct
17 Correct 58 ms 16420 KB Output is correct
18 Correct 21 ms 10272 KB Output is correct
19 Correct 69 ms 19120 KB Output is correct
20 Correct 93 ms 19432 KB Output is correct
21 Correct 66 ms 17012 KB Output is correct
22 Correct 62 ms 16440 KB Output is correct
23 Correct 71 ms 19968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9768 KB Output is correct
2 Correct 9 ms 9792 KB Output is correct
3 Correct 10 ms 9792 KB Output is correct
4 Correct 7 ms 9668 KB Output is correct
5 Correct 7 ms 9676 KB Output is correct
6 Correct 10 ms 9804 KB Output is correct
7 Correct 9 ms 9652 KB Output is correct
8 Correct 9 ms 9792 KB Output is correct
9 Correct 12 ms 9804 KB Output is correct
10 Correct 9 ms 9652 KB Output is correct
11 Correct 16 ms 11396 KB Output is correct
12 Correct 26 ms 12612 KB Output is correct
13 Correct 50 ms 18776 KB Output is correct
14 Correct 70 ms 19116 KB Output is correct
15 Correct 91 ms 19452 KB Output is correct
16 Correct 72 ms 17068 KB Output is correct
17 Correct 58 ms 16420 KB Output is correct
18 Correct 21 ms 10272 KB Output is correct
19 Correct 69 ms 19120 KB Output is correct
20 Correct 93 ms 19432 KB Output is correct
21 Correct 66 ms 17012 KB Output is correct
22 Correct 62 ms 16440 KB Output is correct
23 Correct 71 ms 19968 KB Output is correct
24 Correct 10 ms 9668 KB Output is correct
25 Correct 17 ms 11456 KB Output is correct
26 Correct 25 ms 12716 KB Output is correct
27 Correct 44 ms 18616 KB Output is correct
28 Correct 68 ms 19096 KB Output is correct
29 Correct 95 ms 19396 KB Output is correct
30 Correct 68 ms 17092 KB Output is correct
31 Correct 61 ms 16640 KB Output is correct
32 Correct 21 ms 10244 KB Output is correct
33 Correct 72 ms 19080 KB Output is correct
34 Correct 94 ms 19376 KB Output is correct
35 Correct 71 ms 17144 KB Output is correct
36 Correct 63 ms 16452 KB Output is correct
37 Correct 70 ms 19884 KB Output is correct
38 Correct 10 ms 9668 KB Output is correct