General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
40732471 Practice:
chihuahua
996D - 10 GNU C++14 Wrong answer on test 4 15 ms 0 KB 2018-07-25 11:15:35 2018-07-25 11:15:35
 
 
→ Source
#include<bits/stdc++.h>
using namespace std;

struct couple
{
	long  l,r,t,value;
};

bool compare(couple a,couple b)
{
	if(a.t<b.t)
	{
		return true;
	}
	else
	{
		if(a.l<b.l)return true;
	}
	return false;
}

int main()
{
	long n;
	cin>>n;
	long a[2*n];
	for(long i = 0 ; i < 2*n ; i++)cin>>a[i];
	vector<long> v[n+1];
	for (int i = 0; i < 2*n; ++i)
	{
		v[a[i]].push_back(i);
	}
	couple c[n+1];
	for (int i = 1; i <= n; ++i)
	{
		c[i].l = v[i][0];
		c[i].r = v[i][1];
		c[i].t = c[i].l+c[i].r;
		c[i].value = i;
		//cout<<c[i].t<<" ";
	}
	sort(c+1,c+n+1,compare);
	//cout<<endl;
	long ans=0;
	for (int i = 1; i <= n; ++i)
	{
		if(c[i].l!=(i-1)*2)ans+=abs(c[i].l-(i-1)*2);
		if(c[i].r!=(i-1)*2+1)ans+=abs(c[i].r-((i-1)*2+1));
	}
	ans/=2;
	cout<<ans<<endl;
	return 0;
}
 
 
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details