Submission #439062

# Submission time Handle Problem Language Result Execution time Memory
439062 2021-06-29T07:08:45 Z adamjinwei Tropical Garden (IOI11_garden) C++14
100 / 100
2923 ms 41332 KB
#include <bits/stdc++.h>
#include "garden.h"
#include "gardenlib.h"
#define inf 1000000007
#define mod 1000000007
#define rnd() rand_num()
#define bigrnd() dis(rand_num)
//#pragma GCC optimize("Ofast","inline","-ffast-math")
//#pragma GCC target("avx,sse2,sse3,sse4,mmx")
//#define int long long
using namespace std;
unsigned sed=std::chrono::system_clock::now().time_since_epoch().count();
mt19937 rand_num(sed);
uniform_int_distribution<long long> dis(0,inf);
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
template <typename T> void write(T x) {
	if (x<0) x=-x,putchar('-');
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int len[2]={inf,inf},color,col[150005][2];
int dist[150005][2][2];
bool vis[150005][2];
vector<int> g[150005];
vector<pair<int,int>> out[150005][2];
void buildgraph(int node,int cur)
{
	if(vis[node][cur]) return;
	vis[node][cur]=1;
	int nnode,nxt;
	if(cur==0) nnode=g[node][0];
	else nnode=(g[node].size()>1?g[node][1]:g[node][0]);
	if(g[nnode][0]==node) nxt=1;
	else nxt=0;
	buildgraph(nnode,nxt);
	out[nnode][nxt].push_back(make_pair(node,cur));
}
void dfs(int node,int w,int d,int s)
{
	if(col[node][w]==color)
	{
		if(w==s) len[s]=d;
		return;
	}
	col[node][w]=color;
	dist[node][w][s]=d;
	for(pair<int,int> i:out[node][w])
		dfs(i.first,i.second,d+1,s);
}
void count_routes(int N,int M,int P,int R[][2],int Q,int G[])
{
	for(int i=0;i<M;++i)
	{
		g[R[i][0]].push_back(R[i][1]);
		g[R[i][1]].push_back(R[i][0]);
	}
	for(int i=0;i<N;++i)
		for(int j=0;j<2;++j)
			if(!vis[i][j])
				buildgraph(i,j);
	for(int i=0;i<N;++i)
		for(int j=0;j<2;++j)
			for(int k=0;k<2;++k)
				dist[i][j][k]=inf;
	color++;
	dfs(P,0,0,0);
	color++;
	dfs(P,1,0,1);
	for(int i=0;i<Q;++i)
	{
		int ans=0;
		for(int j=0;j<N;++j)
		{
			if(G[i]>=dist[j][0][0]&&(G[i]-dist[j][0][0])%len[0]==0) ans++;
			if(G[i]>=dist[j][0][1]&&(G[i]-dist[j][0][1])%len[1]==0) ans++;
		}
		answer(ans);
	}
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 11084 KB Output is correct
2 Correct 8 ms 10956 KB Output is correct
3 Correct 9 ms 11016 KB Output is correct
4 Correct 7 ms 10880 KB Output is correct
5 Correct 8 ms 10816 KB Output is correct
6 Correct 8 ms 11084 KB Output is correct
7 Correct 8 ms 10856 KB Output is correct
8 Correct 9 ms 11016 KB Output is correct
9 Correct 11 ms 11212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 11084 KB Output is correct
2 Correct 8 ms 10956 KB Output is correct
3 Correct 9 ms 11016 KB Output is correct
4 Correct 7 ms 10880 KB Output is correct
5 Correct 8 ms 10816 KB Output is correct
6 Correct 8 ms 11084 KB Output is correct
7 Correct 8 ms 10856 KB Output is correct
8 Correct 9 ms 11016 KB Output is correct
9 Correct 11 ms 11212 KB Output is correct
10 Correct 8 ms 11004 KB Output is correct
11 Correct 32 ms 13816 KB Output is correct
12 Correct 44 ms 15876 KB Output is correct
13 Correct 67 ms 33348 KB Output is correct
14 Correct 166 ms 26756 KB Output is correct
15 Correct 272 ms 27196 KB Output is correct
16 Correct 163 ms 22852 KB Output is correct
17 Correct 168 ms 21344 KB Output is correct
18 Correct 43 ms 15556 KB Output is correct
19 Correct 183 ms 26852 KB Output is correct
20 Correct 237 ms 27052 KB Output is correct
21 Correct 161 ms 22852 KB Output is correct
22 Correct 134 ms 21380 KB Output is correct
23 Correct 211 ms 28588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 11084 KB Output is correct
2 Correct 8 ms 10956 KB Output is correct
3 Correct 9 ms 11016 KB Output is correct
4 Correct 7 ms 10880 KB Output is correct
5 Correct 8 ms 10816 KB Output is correct
6 Correct 8 ms 11084 KB Output is correct
7 Correct 8 ms 10856 KB Output is correct
8 Correct 9 ms 11016 KB Output is correct
9 Correct 11 ms 11212 KB Output is correct
10 Correct 8 ms 11004 KB Output is correct
11 Correct 32 ms 13816 KB Output is correct
12 Correct 44 ms 15876 KB Output is correct
13 Correct 67 ms 33348 KB Output is correct
14 Correct 166 ms 26756 KB Output is correct
15 Correct 272 ms 27196 KB Output is correct
16 Correct 163 ms 22852 KB Output is correct
17 Correct 168 ms 21344 KB Output is correct
18 Correct 43 ms 15556 KB Output is correct
19 Correct 183 ms 26852 KB Output is correct
20 Correct 237 ms 27052 KB Output is correct
21 Correct 161 ms 22852 KB Output is correct
22 Correct 134 ms 21380 KB Output is correct
23 Correct 211 ms 28588 KB Output is correct
24 Correct 9 ms 10828 KB Output is correct
25 Correct 146 ms 13912 KB Output is correct
26 Correct 215 ms 15924 KB Output is correct
27 Correct 2567 ms 33384 KB Output is correct
28 Correct 1242 ms 26768 KB Output is correct
29 Correct 2868 ms 27188 KB Output is correct
30 Correct 1713 ms 22976 KB Output is correct
31 Correct 1698 ms 21472 KB Output is correct
32 Correct 242 ms 15928 KB Output is correct
33 Correct 1211 ms 26848 KB Output is correct
34 Correct 2923 ms 27164 KB Output is correct
35 Correct 1802 ms 22948 KB Output is correct
36 Correct 1976 ms 21556 KB Output is correct
37 Correct 1084 ms 28740 KB Output is correct
38 Correct 2349 ms 41332 KB Output is correct