답안 #14203

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
14203 2015-05-04T14:19:25 Z gs14004 개구리 (KOI13_frog) C++14
22 / 22
194 ms 11360 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(-1e9,-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(-1e9,-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]) - vy.begin());
        pi t = rmq.q(low,high-1);
        if(t.first >= vx[a[i].x] - r - d){
            graph[a[i].num].push_back(t.second);
            graph[t.second].push_back(a[i].num);
        }
        low = (int)(lower_bound(vy.begin(),vy.end(),vy[a[i].y]) - vy.begin());
        high = (int)(lower_bound(vy.begin(),vy.end(),vy[a[i].y]+r+1) - vy.begin());
        t = rmq.q(low,high-1);
        if(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(vx[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]) - vx.begin());
        pi t = rmq.q(low,high-1);
        if(t.first >= vy[a[i].y] - r - d){
            graph[a[i].num].push_back(t.second);
            graph[t.second].push_back(a[i].num);
        }
        low = (int)(lower_bound(vx.begin(),vx.end(),vx[a[i].x]) - vx.begin());
        high = (int)(lower_bound(vx.begin(),vx.end(),vx[a[i].x]+r+1) - vx.begin());
        t = rmq.q(low,high-1);
        if(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(vy[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);
    for (int i=0; i<n; i++) {
        if(a[i].x == 0 && a[i].y == 0){
            q.push(i);
            vis[i] = 1;
        }
    }
    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 0 ms 7544 KB Output is correct
3 Correct 2 ms 7544 KB Output is correct
4 Correct 2 ms 7544 KB Output is correct
5 Correct 2 ms 7544 KB Output is correct
6 Correct 0 ms 7544 KB Output is correct
7 Correct 0 ms 7544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 7544 KB Output is correct
2 Correct 0 ms 7544 KB Output is correct
3 Correct 0 ms 7544 KB Output is correct
4 Correct 0 ms 7544 KB Output is correct
5 Correct 3 ms 7544 KB Output is correct
6 Correct 1 ms 7544 KB Output is correct
7 Correct 0 ms 7544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7544 KB Output is correct
2 Correct 0 ms 7544 KB Output is correct
3 Correct 3 ms 7544 KB Output is correct
4 Correct 3 ms 7544 KB Output is correct
5 Correct 4 ms 7544 KB Output is correct
6 Correct 4 ms 7544 KB Output is correct
7 Correct 7 ms 7544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 7544 KB Output is correct
2 Correct 13 ms 7544 KB Output is correct
3 Correct 9 ms 7676 KB Output is correct
4 Correct 14 ms 7676 KB Output is correct
5 Correct 12 ms 7676 KB Output is correct
6 Correct 15 ms 7808 KB Output is correct
7 Correct 15 ms 7676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 7544 KB Output is correct
2 Correct 3 ms 7544 KB Output is correct
3 Correct 10 ms 7544 KB Output is correct
4 Correct 11 ms 7676 KB Output is correct
5 Correct 21 ms 7696 KB Output is correct
6 Correct 24 ms 7960 KB Output is correct
7 Correct 55 ms 8068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 8992 KB Output is correct
2 Correct 135 ms 8456 KB Output is correct
3 Correct 178 ms 11228 KB Output is correct
4 Correct 152 ms 8456 KB Output is correct
5 Correct 167 ms 8720 KB Output is correct
6 Correct 182 ms 11360 KB Output is correct
7 Correct 194 ms 11360 KB Output is correct