#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
using namespace std;
struct leaf {
int X;
int Y;
} Leaf[100001];
struct line {
int X;
int Y;
int IO;
int Num;
bool operator < (line K) const {return X<K.X || (X==K.X && IO<K.IO);}
} Line[200001];
multimap <int,int> Map;
multimap <int,int> :: iterator itLeft, itRight;
vector <int> Edge[100001];
queue <int> Q;
int N, R, D, S, Check[100001], Ans;
void makeLine(void) {
int i;
for(i=1 ; i<=N ; i++) {
Line[2*i-1]={Leaf[i].X-D,Leaf[i].Y,0,i};
Line[2*i ]={Leaf[i].X+R,Leaf[i].Y,1,i};
}
sort(Line+1,Line+2*N+1);
}
void swapLeaf(void) {
int i, temp;
for(i=1 ; i<=N ; i++) {
temp=Leaf[i].X;
Leaf[i].X=Leaf[i].Y;
Leaf[i].Y=temp;
}
}
void makeEdge(void) {
int i;
for(i=1 ; i<=2*N ; i++) {
if(Line[i].IO)
Map.erase(Line[i].Y);
else {
itLeft =Map.lower_bound(Line[i].Y-R);
itRight=Map.upper_bound(Line[i].Y+R);
while(itLeft!=itRight) {
Edge[Line[i].Num ].push_back(itLeft->second);
Edge[itLeft->second].push_back(Line[i].Num );
itLeft++;
}
Map.insert(make_pair(Line[i].Y,Line[i].Num));
}
}
}
void BFS(void) {
int i, j, now;
Check[S]=1;
Q.push(S);
while(!Q.empty()) {
now=Q.front();
Q.pop();
Ans=max(Ans,Leaf[now].X+Leaf[now].Y+2*R);
j=Edge[now].size();
for(i=0 ; i<j ; i++)
if(!Check[Edge[now][i]]) {
Check[Edge[now][i]]=1;
Q.push(Edge[now][i]);
}
}
}
int main(void) {
int i, inp1, inp2;
scanf("%d %d",&N,&R);
for(i=1 ; i<=N ; i++) {
scanf("%d %d",&inp1,&inp2);
Leaf[i]={inp1,inp2};
if(!inp1 && !inp2)
S=i;
}
scanf("%d",&D);
makeLine();
makeEdge();
swapLeaf();
makeLine();
makeEdge();
BFS();
printf("%d",Ans);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
7888 KB |
Output is correct |
2 |
Correct |
0 ms |
7888 KB |
Output is correct |
3 |
Correct |
0 ms |
7888 KB |
Output is correct |
4 |
Correct |
0 ms |
7888 KB |
Output is correct |
5 |
Incorrect |
0 ms |
7888 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
7888 KB |
Output is correct |
2 |
Incorrect |
0 ms |
7888 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
7888 KB |
Output is correct |
2 |
Correct |
0 ms |
7888 KB |
Output is correct |
3 |
Correct |
0 ms |
7888 KB |
Output is correct |
4 |
Correct |
0 ms |
7888 KB |
Output is correct |
5 |
Correct |
0 ms |
7888 KB |
Output is correct |
6 |
Correct |
0 ms |
7888 KB |
Output is correct |
7 |
Correct |
4 ms |
7888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7888 KB |
Output is correct |
2 |
Correct |
8 ms |
7888 KB |
Output is correct |
3 |
Correct |
4 ms |
7888 KB |
Output is correct |
4 |
Incorrect |
0 ms |
7888 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7888 KB |
Output is correct |
2 |
Correct |
4 ms |
7888 KB |
Output is correct |
3 |
Correct |
4 ms |
7888 KB |
Output is correct |
4 |
Correct |
8 ms |
8020 KB |
Output is correct |
5 |
Correct |
8 ms |
7888 KB |
Output is correct |
6 |
Incorrect |
20 ms |
8284 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
64 ms |
9868 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |