Submission #412805

# Submission time Handle Problem Language Result Execution time Memory
412805 2021-05-27T14:51:04 Z jeqcho Tropical Garden (IOI11_garden) C++17
100 / 100
2850 ms 39736 KB
#include "garden.h"
#include "gardenlib.h"


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpi;

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

#define pb push_back
#define rsz resize
#define sz(x) int(x.size())
#define all(x) begin(x), end(x)
#define fi first
#define se second

int const n=15e4+3;
vpi adj[n];
vi pre[2*n];
int d[2*n][2];
bitset<2>vis[2*n];
int cycle[2];
int P;
int N;

void dfs(int now, int w, bool r)
{
	if(vis[now][r])
	{
		if(now==P+r*N)
		{
			cycle[r]=w;
		}
		return;
	}
	d[now][r]=w;
	vis[now][r]=1;
	trav(chi,pre[now])
	{
		dfs(chi,w+1,r);
	}
}

void count_routes(int N1, int M, int p, int R[][2], int Q, int G[]){
	N=N1;
	P=p;
	F0R(i,M)
	{
		int u = R[i][0];
		int v = R[i][1];
		adj[u].pb({M-i,v});
		adj[v].pb({M-i,u});
	}
	F0R(i,N)
	{
		sort(all(adj[i]));
		reverse(all(adj[i]));
	}
	F0R(i,N)
	{
		int nxt = adj[i][0].se;
		if(adj[nxt][0].se == i)
		{
			nxt+=N;
		}
		pre[nxt].pb(i);
		if(sz(adj[i])>1)nxt = adj[i][1].se;
		else nxt = adj[i][0].se;
		if(adj[nxt][0].se == i)
		{
			nxt+=N;
		}
		pre[nxt].pb(i+N);
	}
	F0R(i,2*N)
	{
		d[i][0]=d[i][1]=-1;
	}
	F0R(r,2)
	{
		cycle[r]=-1;
	}
	dfs(P,0,0);
	dfs(P+N,0,1);
	
	F0R(j,Q)
	{
		int ans=0;
		F0R(i,N)
		{
			F0R(r,2)
			{
				if(d[i][r]!=-1
				&&G[j]>=d[i][r])
				{
					if(G[j]-d[i][r]==0)
					{
						++ans;
					}
					else if(cycle[r]!=-1
					&&(G[j]-d[i][r])%cycle[r]==0)
					{
						++ans;
					}
				}
			}
		}
		answer(ans);
	}
}

# Verdict Execution time Memory Grader output
1 Correct 8 ms 10996 KB Output is correct
2 Correct 8 ms 11036 KB Output is correct
3 Correct 8 ms 11016 KB Output is correct
4 Correct 7 ms 10824 KB Output is correct
5 Correct 7 ms 10876 KB Output is correct
6 Correct 8 ms 11084 KB Output is correct
7 Correct 7 ms 10892 KB Output is correct
8 Correct 8 ms 10956 KB Output is correct
9 Correct 10 ms 11212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 10996 KB Output is correct
2 Correct 8 ms 11036 KB Output is correct
3 Correct 8 ms 11016 KB Output is correct
4 Correct 7 ms 10824 KB Output is correct
5 Correct 7 ms 10876 KB Output is correct
6 Correct 8 ms 11084 KB Output is correct
7 Correct 7 ms 10892 KB Output is correct
8 Correct 8 ms 10956 KB Output is correct
9 Correct 10 ms 11212 KB Output is correct
10 Correct 7 ms 10900 KB Output is correct
11 Correct 18 ms 13560 KB Output is correct
12 Correct 36 ms 15916 KB Output is correct
13 Correct 64 ms 31116 KB Output is correct
14 Correct 130 ms 27460 KB Output is correct
15 Correct 167 ms 27872 KB Output is correct
16 Correct 137 ms 24072 KB Output is correct
17 Correct 115 ms 22932 KB Output is correct
18 Correct 42 ms 16012 KB Output is correct
19 Correct 128 ms 27516 KB Output is correct
20 Correct 169 ms 28060 KB Output is correct
21 Correct 124 ms 23916 KB Output is correct
22 Correct 141 ms 22852 KB Output is correct
23 Correct 137 ms 28964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 10996 KB Output is correct
2 Correct 8 ms 11036 KB Output is correct
3 Correct 8 ms 11016 KB Output is correct
4 Correct 7 ms 10824 KB Output is correct
5 Correct 7 ms 10876 KB Output is correct
6 Correct 8 ms 11084 KB Output is correct
7 Correct 7 ms 10892 KB Output is correct
8 Correct 8 ms 10956 KB Output is correct
9 Correct 10 ms 11212 KB Output is correct
10 Correct 7 ms 10900 KB Output is correct
11 Correct 18 ms 13560 KB Output is correct
12 Correct 36 ms 15916 KB Output is correct
13 Correct 64 ms 31116 KB Output is correct
14 Correct 130 ms 27460 KB Output is correct
15 Correct 167 ms 27872 KB Output is correct
16 Correct 137 ms 24072 KB Output is correct
17 Correct 115 ms 22932 KB Output is correct
18 Correct 42 ms 16012 KB Output is correct
19 Correct 128 ms 27516 KB Output is correct
20 Correct 169 ms 28060 KB Output is correct
21 Correct 124 ms 23916 KB Output is correct
22 Correct 141 ms 22852 KB Output is correct
23 Correct 137 ms 28964 KB Output is correct
24 Correct 8 ms 10828 KB Output is correct
25 Correct 182 ms 13696 KB Output is correct
26 Correct 289 ms 16032 KB Output is correct
27 Correct 2543 ms 31212 KB Output is correct
28 Correct 1436 ms 27636 KB Output is correct
29 Correct 2798 ms 28032 KB Output is correct
30 Correct 1686 ms 24132 KB Output is correct
31 Correct 1630 ms 22860 KB Output is correct
32 Correct 309 ms 16072 KB Output is correct
33 Correct 1449 ms 27576 KB Output is correct
34 Correct 2850 ms 27988 KB Output is correct
35 Correct 1842 ms 23976 KB Output is correct
36 Correct 1637 ms 22792 KB Output is correct
37 Correct 1305 ms 29084 KB Output is correct
38 Correct 2312 ms 39736 KB Output is correct