답안 #12889

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
12889 2015-01-18T15:49:40 Z baneling100 개구리 (KOI13_frog) C++
22 / 22
632 ms 63592 KB
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#define INF 0x7fffffff

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];
typedef pair <int,int> ppair;
multimap <ppair,int> Map;
multimap <ppair,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(make_pair(Line[i].Y,Line[i].X));
        else {
            itLeft =Map.lower_bound(make_pair(Line[i].Y-R,-INF));
            itRight=Map.upper_bound(make_pair(Line[i].Y+R,INF));
            while(itLeft!=itRight) {
                Edge[Line[i].Num   ].push_back(itLeft->second);
                Edge[itLeft->second].push_back(Line[i].Num   );
                itLeft++;
            }
            Map.insert(make_pair(make_pair(Line[i].Y,Line[i].X+D+R),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 Correct 0 ms 7888 KB Output is correct
6 Correct 0 ms 7888 KB Output is correct
7 Correct 0 ms 7888 KB Output is correct
# 결과 실행 시간 메모리 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 8020 KB Output is correct
7 Correct 4 ms 8152 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 7888 KB Output is correct
2 Correct 8 ms 7888 KB Output is correct
3 Correct 4 ms 8020 KB Output is correct
4 Correct 8 ms 7888 KB Output is correct
5 Correct 4 ms 7888 KB Output is correct
6 Correct 12 ms 9868 KB Output is correct
7 Correct 12 ms 10000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 7888 KB Output is correct
2 Correct 4 ms 8284 KB Output is correct
3 Correct 4 ms 7888 KB Output is correct
4 Correct 12 ms 8944 KB Output is correct
5 Correct 16 ms 7888 KB Output is correct
6 Correct 36 ms 11320 KB Output is correct
7 Correct 40 ms 8548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 104 ms 15016 KB Output is correct
2 Correct 68 ms 9076 KB Output is correct
3 Correct 248 ms 20692 KB Output is correct
4 Correct 76 ms 8284 KB Output is correct
5 Correct 72 ms 8548 KB Output is correct
6 Correct 632 ms 63592 KB Output is correct
7 Correct 392 ms 36136 KB Output is correct