Submission #5542578


Source Code Expand

// È¥°É£¡Æ¤¿¨Çð! °ÑAC´ø»ØÀ´£¡
//      ¤Ø¡¡¡¡¡¡¡¡¡¡£¯|
// ¡¡¡¡/£Ü7¡¡¡¡¡¡ ¡Ï£ß/
// ¡¡ /¡¡©¦¡¡¡¡ £¯¡¡£¯								AC		AC		AC		AC
//    ©¦¡¡Z £ß,£¼¡¡£¯¡¡¡¡ /`©c						AC		AC		AC		AC
//    ©¦¡¡¡¡¡¡¡¡¡¡©c¡¡¡¡ /¡¡¡¡¡µ					AC		AC		AC		AC
// ¡¡Y¡¡¡¡¡¡¡¡¡¡`¡¡ /¡¡¡¡/  /						AC		AC		AC		AC
// ¡¡Øé¡ñ¡¡.¡¡¡ñ¡¡¡¡¡´¡¡/¡¡/						AC		AC		AC		AC
// ¡¡()¡¡ ¤Ø¡¡¡¡¡¡¡¡|¡¡£Ü¡´							AC		AC		AC		AC
// ¡¡¡¡>- ._¡¡ ¥£¡¡ ©¦ £¯£¯							AC		AC		AC		AC
// ¡¡ / ¤Ø¡¡¡¡ /¡¡/£¼| £Ü£Ü							AC		AC		AC		AC
// ¡¡ ©c_/¡¡¡¡(_£¯¡¡ ©¦£¯£¯							AC		AC		AC		AC
// ¡¡¡¡ 7¡¡¡¡¡¡¡¡¡¡¡¡¡¡|£¯							AC		AC		AC		AC
// ¡¡¡¡ £¾¨Dr£þ£þ`-¨D£ß/							AC		AC		AC		AC
//**************************************Accepted*****************************************//

#include<bits/stdc++.h>

#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define Unique(x) x.erase(unique(all(x)),x.end);

#define CIN_FILE "input.txt"
#define COUT_FILE "output.txt"

using namespace std;

const int dx[]={-1,0,1,0};
const int dy[]={0,-1,0,1};

typedef long long ll;

int n,x[100010],y[100010],pa[100010];
pair<int,int> sx[100010],sy[100010];
int ans;

inline bool cmp(pair<int,int> x,pair<int,int> y){return x.first<y.first;}

inline int fnd(int x){return (x==pa[x] ? x : fnd(pa[x]));}

int Onion(int x,int y)
{
	x=fnd(x),y=fnd(y);
	
	if(x==y)return 0;
	
	pa[x]=y;
	return 1;
}

set<pair<int,pair<int,int> > > st;

int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>x[i]>>y[i];
		pa[i]=i;
		sx[i]=mp(x[i],i),sy[i]=mp(y[i],i);
	}
	
	sort(sx,sx+n,cmp);
	sort(sy,sy+n,cmp);
	
	for(int i=0;i<n-1;i++)
	{
		st.insert(mp(min((abs(x[sx[i].second]-x[sx[i+1].second])),(abs(y[sx[i].second]-y[sx[i+1].second]))),mp(sx[i].second,sx[i+1].second)));
		st.insert(mp(min((abs(x[sy[i].second]-x[sy[i+1].second])),(abs(y[sy[i].second]-y[sy[i+1].second]))),mp(sy[i].second,sy[i+1].second)));
	}
	
	while(!st.empty())
	{
		pair<int,pair<int,int> > cur=*(st.begin());
		st.erase(cur);
		
		int u=cur.second.first,v=cur.second.second;
		
		ans+=(Onion(u,v)*(min((abs(x[u]-x[v])),(abs(y[u]-y[v])))));
	}
	
	cout<<ans;
	
	//printf("Time used = %.6f",(double)(clock())/CLOCKS_PER_SEC);
	return 0;
}

Submission Info

Submission Time
Task D - Built?
User vjudge2
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2440 Byte
Status TLE
Exec Time 2104 ms
Memory 17600 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 2
AC × 13
TLE × 15
Set Name Test Cases
Sample s1.txt, s2.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, s1.txt, s2.txt
Case Name Status Exec Time Memory
01.txt TLE 2104 ms 15488 KB
02.txt TLE 2104 ms 17600 KB
03.txt TLE 2104 ms 15488 KB
04.txt TLE 2104 ms 15488 KB
05.txt TLE 2104 ms 15488 KB
06.txt TLE 2104 ms 15488 KB
07.txt TLE 2104 ms 15488 KB
08.txt TLE 2104 ms 15488 KB
09.txt TLE 2104 ms 15488 KB
10.txt TLE 2104 ms 15488 KB
11.txt TLE 2104 ms 17536 KB
12.txt TLE 2104 ms 15488 KB
13.txt TLE 2104 ms 15488 KB
14.txt TLE 2104 ms 15488 KB
15.txt AC 90 ms 9216 KB
16.txt AC 134 ms 15488 KB
17.txt AC 140 ms 15488 KB
18.txt AC 93 ms 9216 KB
19.txt AC 91 ms 9216 KB
20.txt AC 125 ms 14336 KB
21.txt AC 119 ms 14208 KB
22.txt AC 127 ms 14208 KB
23.txt AC 52 ms 9216 KB
24.txt TLE 2104 ms 15488 KB
25.txt AC 1 ms 256 KB
26.txt AC 1 ms 256 KB
s1.txt AC 1 ms 256 KB
s2.txt AC 1 ms 256 KB