답안 #133023

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
133023 2019-07-20T05:16:50 Z zozder 열대 식물원 (Tropical Garden) (IOI11_garden) C++14
0 / 100
8 ms 5880 KB
#include "garden.h"
#include "gardenlib.h"
#include <iostream>
#include <cstdlib>
#define maxn 100005
using namespace std;

int map[2*maxn][3],o;
int real_map[2*maxn][3];
int sort[maxn][3];
int ans=0;
int t[2*maxn];

int compare(const void*x ,const void *y)
{
	return ((int*)y)[2] - ((int*)x)[2];
}

void find(int x, int location, int g, int lp)
{
//	cout<<x<<"\t"<<location<<"\t"<<g<<endl;
	if(g==0)
	{
		if(x==location)ans++;
		return ;
	}
	int p=x;
	p=real_map[p][0];
	if(real_map[p][1]==lp&&p!=-1)p=real_map[p][0];
	if(p==-1)find(lp,location,g-1,x);
	else find(real_map[p][1],location,g-1,x);
}

void count_routes(int n, int m, int location, int r[][2], int q, int g[])
{
	//Q=1
	for(int i=0;i<2*maxn;i++)
	{
		map[i][0]=-1;
		real_map[i][0]=-1;
		t[i]=0;
	}
	o=n-1;
	for(int i=0;i<m;i++)
	{
		o++;
		map[o][1]=r[i][1];
		map[o][2]=i;
		map[o][0]=map[r[i][0]][0];
		map[r[i][0]][0]=o;
		o++;
		map[o][1]=r[i][0];
		map[o][2]=i;
		map[o][0]=map[r[i][1]][0];
		map[r[i][1]][0]=o;
	}
/*	for(int i=0;i<=o;i++)cout<<i<<"\t";cout<<endl;
	for(int i=0;i<=o;i++)cout<<map[i][0]<<"\t";cout<<endl;
	for(int i=0;i<=o;i++)cout<<map[i][1]<<"\t";cout<<endl;*/
	o=n-1;
	for(int i=0;i<m;i++)//編號越少越美麗 
	{
		int oo=0;
		int p=i;
		while(map[p][0]!=-1)
		{
			p=map[p][0];
			oo++;
			sort[oo][0]=i;
			sort[oo][1]=map[p][1];
			sort[oo][2]=map[p][2];
		}
		qsort(sort+1,oo,sizeof(int)*3,compare);
//		for(int j=1;j<=oo;j++)cout<<sort[j][2]<<" ";cout<<endl;
		for(int j=1;j<=oo;j++)
		{
			o++;
			real_map[o][1]=sort[j][1];
			real_map[o][2]=sort[j][2];
			real_map[o][0]=real_map[i][0];
			real_map[i][0]=o;
		}
	}
/*	for(int i=0;i<=o+2;i++)cout<<i<<"\t";cout<<endl;
	for(int i=0;i<=o+2;i++)cout<<real_map[i][0]<<"\t";cout<<endl;
	for(int i=0;i<=o+2;i++)cout<<real_map[i][1]<<"\t";cout<<endl;*/
	
	for(int j=1;j<=q;j++)
	{
		ans=0;
		for(int i=0;i<n;i++)
		{
//		cout<<i<<":"<<endl;
			find(i,location,g[j-1],-1);
		}
		answer(ans);
	}
	
}

# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5752 KB Output is correct
2 Correct 7 ms 5752 KB Output is correct
3 Correct 7 ms 5880 KB Output is correct
4 Correct 7 ms 5756 KB Output is correct
5 Correct 6 ms 5880 KB Output is correct
6 Incorrect 8 ms 5852 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5752 KB Output is correct
2 Correct 7 ms 5752 KB Output is correct
3 Correct 7 ms 5880 KB Output is correct
4 Correct 7 ms 5756 KB Output is correct
5 Correct 6 ms 5880 KB Output is correct
6 Incorrect 8 ms 5852 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5752 KB Output is correct
2 Correct 7 ms 5752 KB Output is correct
3 Correct 7 ms 5880 KB Output is correct
4 Correct 7 ms 5756 KB Output is correct
5 Correct 6 ms 5880 KB Output is correct
6 Incorrect 8 ms 5852 KB Output isn't correct
7 Halted 0 ms 0 KB -