This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct point{
int x,color;
bool operator<(point t){
if (color!=t.color)
return color<t.color;
return x<t.x;
}
};
const int INF=1e9+1;
int N;
point A[100001];
ll Ans;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>N;
for (int i=1; i<=N; i++)
cin>>A[i].x>>A[i].color;
sort(A+1,A+1+N);
for (int i=1; i<=N; i++){
int t=INF;
if (i>1&&A[i-1].color==A[i].color)
t=min(t,A[i].x-A[i-1].x);
if (i<N&&A[i+1].color==A[i].color)
t=min(t,A[i+1].x-A[i].x);
if (t<INF)
Ans+=t;
}
cout<<Ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |