Submission #63908

# Submission time Handle Problem Language Result Execution time Memory
63908 2018-08-03T06:50:50 Z 강태규(#1867) Park (BOI16_park) C++11
100 / 100
936 ms 31440 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;

const llong linf = 5e18;
const int inf = 1e9 + 7;
int n, m, w, h;

struct evt {
    int r, x, y;
    evt(int x, int y, int r) : r(r), x(x), y(y) {}
    bool operator<(const evt &p) const {
        return r < p.r;
    }
};

struct tree {
    int x, y, r;
    void scan() {
        scanf("%d%d%d", &x, &y, &r);
    }
    int getWallCol(int t) {
        if (t == 0) return (y - r) / 2 + 1;
        if (t == 1) return (w - x - r) / 2 + 1;
        if (t == 2) return (h - y - r) / 2 + 1;
        return (x - r) / 2 + 1;
    }
} ts[2000];

llong sq(llong x) {
    if (x > inf + inf) return linf;
    return x * x;
}

int getTreeCol(tree a, tree b) {
    int s = 0, e = inf;
    llong d = sq(a.x - b.x) + sq(a.y - b.y);
    while (s < e) {
        int m = (s + e) / 2;
        llong md = sq((llong)a.r + b.r + m + m);
        if (d < md) e = m;
        else s = m + 1;
    }
    return s;
}

int par[2004];
int find(int x) {
    if (par[x] != x) return par[x] = find(par[x]);
    return x;
}

int merge(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return 0;
    par[x] = y;
    return 1;
}

int connect(int x, int y) {
    return find(n + x) == find(n + y);
}

struct query {
    int r, e, i;
    void scan(int idx) {
        i = idx;
        scanf("%d%d", &r, &e);
        --e;
    }
    bool operator<(const query &q) const {
        return r < q.r;
    }
} qs[100000];

vector<int> ans[100000];

int main() {
    scanf("%d%d%d%d", &n, &m, &w, &h);
    for (int i = 0; i < n; ++i) {
        ts[i].scan();
    }
    vector<evt> ev;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < i; ++j) {
            ev.emplace_back(i, j, getTreeCol(ts[i], ts[j]));
        }
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 4; ++j) {
            ev.emplace_back(i, n + j, ts[i].getWallCol(j));
        }
    }
    for (int i = 0; i < n + 4; ++i) par[i] = i;
    for (int i = 0; i < m; ++i) qs[i].scan(i);
    sort(qs, qs + m);
    sort(ev.begin(), ev.end());
    for (int i = 0, j = 0; i < m; ++i) {
        while (j < ev.size() && ev[j].r <= qs[i].r) {
            merge(ev[j].x, ev[j].y);
            ++j;
        }
        int it = qs[i].i;
        int e = qs[i].e;
        ans[it].push_back(e);
        if (!connect(e, (e + 1) % 4) && !connect(e, (e + 2) % 4) 
            && !connect(e, (e + 3) % 4)) ans[it].push_back((e + 1) % 4);
        if (!connect((e + 3) % 4, e) && !connect((e + 3) % 4, (e + 1) % 4) 
            && !connect((e + 3) % 4, (e + 2) % 4))
            ans[it].push_back((e + 3) % 4);
        
        if (!connect(e, (e + 2) % 4) && !connect((e + 1) % 4, (e + 2) % 4) 
            && !connect(e, (e + 3) % 4) && !connect((e + 1) % 4, (e + 3) % 4))
            ans[it].push_back((e + 2) % 4);
    }
    for (int i = 0; i < m; ++i) {
        sort(ans[i].begin(), ans[i].end());
        for (int j : ans[i]) printf("%d", j + 1);
        printf("\n");
    }
	return 0;
}

Compilation message

park.cpp: In function 'int main()':
park.cpp:116:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while (j < ev.size() && ev[j].r <= qs[i].r) {
                ~~^~~~~~~~~~~
park.cpp:96:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d%d", &n, &m, &w, &h);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
park.cpp: In member function 'void tree::scan()':
park.cpp:36:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d", &x, &y, &r);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
park.cpp: In member function 'void query::scan(int)':
park.cpp:85:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &r, &e);
         ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 724 ms 27464 KB Output is correct
2 Correct 710 ms 27752 KB Output is correct
3 Correct 726 ms 27752 KB Output is correct
4 Correct 765 ms 27752 KB Output is correct
5 Correct 700 ms 27752 KB Output is correct
6 Correct 740 ms 27752 KB Output is correct
7 Correct 706 ms 27752 KB Output is correct
8 Correct 649 ms 27752 KB Output is correct
9 Correct 5 ms 27752 KB Output is correct
10 Correct 4 ms 27752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 116 ms 27752 KB Output is correct
2 Correct 130 ms 27752 KB Output is correct
3 Correct 119 ms 27752 KB Output is correct
4 Correct 124 ms 27752 KB Output is correct
5 Correct 113 ms 27752 KB Output is correct
6 Correct 117 ms 27752 KB Output is correct
7 Correct 107 ms 27752 KB Output is correct
8 Correct 102 ms 27752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 724 ms 27464 KB Output is correct
2 Correct 710 ms 27752 KB Output is correct
3 Correct 726 ms 27752 KB Output is correct
4 Correct 765 ms 27752 KB Output is correct
5 Correct 700 ms 27752 KB Output is correct
6 Correct 740 ms 27752 KB Output is correct
7 Correct 706 ms 27752 KB Output is correct
8 Correct 649 ms 27752 KB Output is correct
9 Correct 5 ms 27752 KB Output is correct
10 Correct 4 ms 27752 KB Output is correct
11 Correct 116 ms 27752 KB Output is correct
12 Correct 130 ms 27752 KB Output is correct
13 Correct 119 ms 27752 KB Output is correct
14 Correct 124 ms 27752 KB Output is correct
15 Correct 113 ms 27752 KB Output is correct
16 Correct 117 ms 27752 KB Output is correct
17 Correct 107 ms 27752 KB Output is correct
18 Correct 102 ms 27752 KB Output is correct
19 Correct 936 ms 31328 KB Output is correct
20 Correct 798 ms 31328 KB Output is correct
21 Correct 869 ms 31440 KB Output is correct
22 Correct 812 ms 31440 KB Output is correct
23 Correct 874 ms 31440 KB Output is correct
24 Correct 880 ms 31440 KB Output is correct