Submission #402912

#TimeUsernameProblemLanguageResultExecution timeMemory
402912jk410화살표 그리기 (KOI18_arrowH)C++17
100 / 100
45 ms2580 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...