Submission #19103

#TimeUsernameProblemLanguageResultExecution timeMemory
19103Namnamseo정전 (OJUZ10_blackout)C++14
100 / 100
69 ms4012 KiB
#include <cstdio> #include <algorithm> using namespace std; typedef pair<int,int> pp; int p[150010]; pp query[300010]; int n,l; int main() { scanf("%d%d",&n,&l); int i; for(i=0;i<n;++i) scanf("%d",p+i); sort(p,p+n); for(i=0;i<n;++i){ query[i*2]={p[i]-l,i%2+1}; query[i*2+1]={p[i]+l,-(i%2+1)}; } sort(query, query+2*n); unsigned int ans=0; int last=0; int on[3]={0,0,0}; for(i=0;i<2*n;++i){ pp& cq=query[i]; if(on[1] && on[2]){ ans+=((unsigned)(cq.first))-last; } if(cq.second>0) ++on[cq.second]; else --on[-cq.second]; last=cq.first; } printf("%u\n",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...