Submission #987442

# Submission time Handle Problem Language Result Execution time Memory
987442 2024-05-22T18:51:18 Z Pyqe Longest Trip (IOI23_longesttrip) C++17
5 / 100
822 ms 5336 KB
#include <bits/stdc++.h>
#include "longesttrip.h"

using namespace std;

long long n,nn[2],dh[100069],pr[100069],ex[2][100069],tmp[100069],sq[100069],zs;
bitset<100069> vtd;

inline bool qr(vector<long long> v,vector<long long> v2)
{
	long long i,sz;
	vector<int> cv,cv2;
	
	sz=v.size();
	for(i=0;i<sz;i++)
	{
		cv.push_back(v[i]-1);
	}
	sz=v2.size();
	for(i=0;i<sz;i++)
	{
		cv2.push_back(v2[i]-1);
	}
	return are_connected(cv,cv2);
}

void dfs(long long x)
{
	long long i;
	
	vtd[x]=1;
	for(i=1;i<=n;i++)
	{
		if(!vtd[i]&&!qr({x},{i}))
		{
			dh[i]=dh[x]+1;
			pr[i]=x;
			dfs(i);
		}
	}
}

bool cmdh(long long x,long long y)
{
	return dh[x]<dh[y];
}

vector<int> longest_trip(int on,int d)
{
	long long i,ii,jj,k,l,sz,e;
	vector<long long> cv,cv2;
	vector<int> ret;
	
	n=on;
	vtd.reset();
	for(ii=0;ii<2;ii++)
	{
		nn[ii]=0;
	}
	for(i=1;i<=n;i++)
	{
		if(!vtd[i])
		{
			dh[i]=0;
			dfs(i);
		}
		e=dh[i]%2;
		nn[e]++;
		ex[e][nn[e]]=i;
	}
	for(ii=0;ii<2;ii++)
	{
		sort(ex[ii]+1,ex[ii]+nn[ii]+1,cmdh);
		sz=0;
		l=-1;
		vtd.reset();
		for(i=nn[ii];i;i--)
		{
			k=ex[ii][i];
			if(l==-1)
			{
				l=k;
			}
			else if(dh[k]!=dh[l])
			{
				l=pr[pr[l]];
				sz++;
				tmp[sz]=l;
				vtd[l]=1;
			}
			if(!vtd[k])
			{
				sz++;
				tmp[sz]=k;
				l=k;
			}
		}
		for(i=1;i<=sz;i++)
		{
			ex[ii][i]=tmp[i];
		}
	}
	zs=0;
	for(i=1;i<=nn[0];i++)
	{
		cv.push_back(ex[0][i]);
	}
	for(i=1;i<=nn[1];i++)
	{
		cv2.push_back(ex[1][i]);
	}
	if(!nn[1]||!qr(cv,cv2))
	{
		e=nn[1]>nn[0];
		for(i=1;i<=nn[e];i++)
		{
			zs++;
			sq[zs]=ex[e][i];
		}
	}
	else
	{
		for(ii=0;ii<2;ii++)
		{
			k=ex[0][1];
			for(jj=0;jj<2;jj++)
			{
				l=ex[1][1];
				if(!zs&&qr({k},{l}))
				{
					for(i=nn[0];i;i--)
					{
						zs++;
						sq[zs]=ex[0][i];
					}
					for(i=1;i<=nn[1];i++)
					{
						zs++;
						sq[zs]=ex[1][i];
					}
				}
				reverse(ex[1]+1,ex[1]+nn[1]+1);
			}
			reverse(ex[0]+1,ex[0]+nn[0]+1);
		}
		if(!zs)
		{
			
		}
	}
	for(i=1;i<=zs;i++)
	{
		ret.push_back(sq[i]-1);
	}
	return ret;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 10 ms 5336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 4440 KB Output is correct
2 Correct 22 ms 4440 KB Output is correct
3 Correct 133 ms 4440 KB Output is correct
4 Correct 360 ms 4688 KB Output is correct
5 Correct 745 ms 4540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 4440 KB Output is correct
2 Correct 22 ms 4440 KB Output is correct
3 Correct 134 ms 4440 KB Output is correct
4 Correct 344 ms 4536 KB Output is correct
5 Correct 779 ms 4536 KB Output is correct
6 Correct 14 ms 4440 KB Output is correct
7 Correct 30 ms 2392 KB Output is correct
8 Correct 125 ms 4536 KB Output is correct
9 Correct 294 ms 4548 KB Output is correct
10 Incorrect 157 ms 4532 KB too many calls
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4440 KB Output is correct
2 Correct 23 ms 4440 KB Output is correct
3 Correct 130 ms 4440 KB Output is correct
4 Correct 327 ms 4540 KB Output is correct
5 Correct 822 ms 4532 KB Output is correct
6 Correct 16 ms 4440 KB Output is correct
7 Correct 20 ms 2392 KB Output is correct
8 Correct 129 ms 2648 KB Output is correct
9 Correct 274 ms 472 KB Output is correct
10 Incorrect 136 ms 4688 KB too many calls
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 2392 KB Output is correct
2 Correct 35 ms 600 KB Output is correct
3 Partially correct 128 ms 4440 KB Output is partially correct
4 Partially correct 403 ms 2488 KB Output is partially correct
5 Partially correct 737 ms 700 KB Output is partially correct
6 Correct 12 ms 2392 KB Output is correct
7 Correct 21 ms 344 KB Output is correct
8 Partially correct 111 ms 4536 KB Output is partially correct
9 Partially correct 261 ms 4688 KB Output is partially correct
10 Incorrect 205 ms 4696 KB too many calls
11 Halted 0 ms 0 KB -