답안 #14200

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
14200 2015-05-04T13:47:26 Z gs14004 개구리 (KOI13_frog) C++14
0 / 22
105 ms 8596 KB
#include <cstdio>
#include <utility>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
typedef pair<int,int> pi;

const int TSIZE = (1<<18) + 1;

struct pos{int x, y, num;};
bool operator<(pos a, pos b){return a.x < b.x;}

int n,r,d;
pos a[100005];
vector<int> vx, vy;

int vis[100005];
vector<int> graph[100005];
queue<int> q;

struct rmq{
    int lim;
    pi tree[TSIZE];
    void init(int n){
        for(lim = 1; lim <= n; lim <<= 1);
        fill(tree,tree+TSIZE,pi(-1,-1));
    }
    void add(int x, pi v){
        x += lim;
        tree[x] = max(tree[x],v);
        while(x > 1){
            x >>= 1;
            tree[x] = max(tree[2*x],tree[2*x+1]);
        }
    }
    pi q(int s, int e){
        s += lim;
        e += lim;
        pi v(-1,-1);
        while(s < e){
            if(s%2 == 1) v = max(v,tree[s++]);
            if(e%2 == 0) v = max(v,tree[e--]);
            s >>= 1;
            e >>= 1;
        }
        if(s == e) v = max(v,tree[s]);
        return v;
    }
}rmq;

bool cmp1(pos a, pos b){
    return a.x < b.x;
}

bool cmp2(pos a, pos b){
    return a.y < b.y;
}

bool cmp3(pos a, pos b){
    return a.num < b.num;
}

void const_graph(){
    sort(a,a+n,cmp1);
    rmq.init(n);
    for (int i=0; i<n; i++){
        int low = (int)(lower_bound(vy.begin(),vy.end(),vy[a[i].y]-r) - vy.begin());
        int high = (int)(lower_bound(vy.begin(),vy.end(),vy[a[i].y]+r+1) - vy.begin());
        pi t = rmq.q(low,high-1);
        if(t.second != -1){
            if(vx[t.first] >= vx[a[i].x] - r - d){
                graph[a[i].num].push_back(t.second);
                graph[t.second].push_back(a[i].num);
            }
        }
        rmq.add(a[i].y,pi(a[i].x,a[i].num));
    }
    sort(a,a+n,cmp2);
    rmq.init(n);
    for (int i=0; i<n; i++) {
        int low = (int)(lower_bound(vx.begin(),vx.end(),vx[a[i].x]-r) - vx.begin());
        int high = (int)(lower_bound(vx.begin(),vx.end(),vx[a[i].x]+r+1) - vx.begin());
        pi t = rmq.q(low,high-1);
        if(t.second != -1){
            if(vy[t.first] >= vy[a[i].y] - r - d){
                graph[a[i].num].push_back(t.second);
                graph[t.second].push_back(a[i].num);
            }
        }
        rmq.add(a[i].x,pi(a[i].y,a[i].num));
    }
}

int main(){
    scanf("%d %d",&n,&r);
    for (int i=0; i<n; i++) {
        scanf("%d %d",&a[i].x,&a[i].y);
        vx.push_back(a[i].x);
        vy.push_back(a[i].y);
        a[i].num = i;
    }
    sort(vx.begin(),vx.end());
    sort(vy.begin(),vy.end());
    vx.resize(unique(vx.begin(),vx.end()) - vx.begin());
    vy.resize(unique(vy.begin(),vy.end()) - vy.begin());
    for (int i=0; i<n; i++) {
        a[i].x = (int)(lower_bound(vx.begin(),vx.end(),a[i].x) - vx.begin());
        a[i].y = (int)(lower_bound(vy.begin(),vy.end(),a[i].y) - vy.begin());
    }
    scanf("%d",&d);
    const_graph();
    sort(a,a+n,cmp3);
    vis[0] = 1;
    q.push(0);
    int ret = 0;
    while (!q.empty()) {
        int qf = q.front();
        q.pop();
        ret = max(ret,vx[a[qf].x] + vy[a[qf].y] + 2 * r);
        for (int i=0; i<graph[qf].size(); i++) {
            int t = graph[qf][i];
            if(vis[t]) continue;
            q.push(t);
            vis[t] = 1;
        }
    }
    printf("%d",ret);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 7544 KB Output is correct
2 Correct 2 ms 7544 KB Output is correct
3 Incorrect 2 ms 7544 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 7544 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 7544 KB Output is correct
2 Incorrect 3 ms 7544 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 7544 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 7544 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 8596 KB Output is correct
2 Incorrect 105 ms 8456 KB Output isn't correct
3 Halted 0 ms 0 KB -