Submission #14217

#TimeUsernameProblemLanguageResultExecution timeMemory
14217khsoo01정전 (OJUZ10_blackout)C++98
0 / 100
51 ms4012 KiB
#include<cstdio> #include<algorithm> #define INF 0x7fffffff using namespace std; int n,l,a[150005],seg[2][150005][2],cnt[2],i,i1,i2,ans; int main() { scanf("%d%d",&n,&l); for(i=0;i<n;i++) { scanf("%d",&a[i]); } std::sort(a,a+n); for(i=0;i<150005;i++){ seg[0][i][0]=-INF; seg[0][i][1]=-INF; seg[1][i][0]=-INF; seg[1][i][1]=-INF; } for(i=0;i<n;i+=2) { if(seg[0][cnt[0]][1]<a[i]-l+1){ cnt[0]++; seg[0][cnt[0]][0]=a[i]-l+1; seg[0][cnt[0]][1]=a[i]+l; } else seg[0][cnt[0]][1]=a[i]+l; } for(i=1;i<n;i+=2) { if(seg[1][cnt[1]][1]<a[i]-l+1){ cnt[1]++; seg[1][cnt[1]][0]=a[i]-l+1; seg[1][cnt[1]][1]=a[i]+l; } else seg[1][cnt[1]][1]=a[i]+l; } for(i1=1,i2=1;i1<=cnt[0]&&i2<=cnt[1];) { if(seg[0][i1][1]<seg[1][i2][0])i2++; else if(seg[1][i2][1]<seg[0][i1][0])i1++; else { ans+=std::min(seg[0][i1][1],seg[1][i2][1])-std::max(seg[0][i1][0],seg[1][i2][0])+1; if(seg[0][i1][1]<seg[1][i2][1])i1++; else if(seg[0][i1][1]>seg[1][i2][1])i2++; else if(seg[0][i1][0]<seg[1][i2][0])i1++; else i2++; } } printf("%d",ans); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...