답안 #442902

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
442902 2021-07-09T10:38:33 Z palilo Park (BOI16_park) C++17
27 / 100
178 ms 16200 KB
#include <bits/stdc++.h>
using namespace std;

#ifdef palilo
template <typename C, typename T = decay_t<decltype(*begin(declval<C>()))>,
    typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator<<(ostream& os, const C& container) {
    stringstream ss;
    ss << '[';
    bool first = true;
    for (const auto& x : container) {
        if (!first) ss << ", ";
        first = false;
        ss << x;
    }
    ss << ']';
    return os << ss.str();
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
    stringstream ss;
    ss << '(' << p.first << ", " << p.second << ')';
    return os << ss.str();
}

template <typename T>
void debug_msg(string name, T arg) {
    cerr << name << " = " << arg << endl;
}

template <typename T1, typename... T2>
void debug_msg(string names, T1 arg, T2... args) {
    cerr << names.substr(0, names.find(',')) << " = " << arg << " | ";
    debug_msg(names.substr(names.find(',') + 2), args...);
}

#define debug(...) cerr << '(' << __LINE__ << ')' << ' ', debug_msg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...)
#endif

template <class T>
bool chmin(T& _old, T _new) { return _old > _new && (_old = _new, true); }
template <class T>
bool chmax(T& _old, T _new) { return _old < _new && (_old = _new, true); }

struct tree {
    int x, y, r;
};

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
#ifdef palilo
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    constexpr int INF = 0x3f3f3f3f;
    int n, m, w, h;
    cin >> n >> m >> w >> h;
    vector<tree> trees(n);
    for (auto& [x, y, r] : trees) {
        cin >> x >> y >> r;
    }
    vector dist(n + 4, vector<int>(n + 4));
    for (int i = 0; i < n - 1; ++i) {
        for (int j = i + 1; j < n; ++j) {
            dist[i][j] = dist[j][i] = (int(hypot(trees[i].x - trees[j].x, trees[i].y - trees[j].y) + 1e-6) - trees[i].r - trees[j].r) / 2;
        }
    }
    for (int i = 0; i < n; ++i) {
        dist[i][n + 0] = dist[n + 0][i] = (trees[i].y - trees[i].r) / 2;
        dist[i][n + 1] = dist[n + 1][i] = (trees[i].x - trees[i].r) / 2;
        dist[i][n + 2] = dist[n + 2][i] = (h - trees[i].y - trees[i].r) / 2;
        dist[i][n + 3] = dist[n + 3][i] = (w - trees[i].x - trees[i].r) / 2;
    }
    for (int i = n; i < n + 4; ++i) {
        for (int j = n; j < n + 4; ++j) {
            dist[i][j] = INF;
        }
    }
    /**
     * [0, n) = trees
     * n + a = sides
     *  3----(2)----2
     *  |           |
     * (1)         (3)
     *  |           |
     *  0----(0)----1
     */
    vector<bool> used(n + 4);
    vector<int> need(n + 4);
    auto solve = [&](int s) {
        fill(used.begin(), used.end(), false);
        fill(need.begin(), need.end(), INF);
        need[n + s] = 0;
        for (int _ = n + 4; _--;) {
            int k = -1;
            for (int i = 0; i < n + 4; ++i) {
                if (!used[i] && (k == -1 || need[i] < need[k])) {
                    k = i;
                }
            }
            assert(~k);
            used[k] = true;
            for (int i = 0; i < n + 4; ++i) {
                if (!used[i]) {
                    chmin(need[i], max(need[k], dist[k][i]));
                }
            }
        }
        debug(s, need);
    };
    //  0 <-> 1 = 0 to others
    //  0 <-> 2 = (0,3) to (1,2)
    //  0 <-> 3 = 1 to others
    //  1 <-> 2 = 3 to others
    //  1 <-> 3 = (0,1) to (2,3)
    //  2 <-> 3 = 2 to others
    array<array<int, 4>, 4> ans;
    memset(ans.data(), 0x3f, sizeof(ans));
    solve(0);
    ans[0][1] = min({need[n + 1], need[n + 2], need[n + 3]});
    chmin(ans[0][2], min(need[n + 1], need[n + 2]));
    chmin(ans[1][3], min(need[n + 2], need[n + 3]));
    solve(1);
    ans[0][3] = min({need[n + 2], need[n + 3], need[n + 0]});
    chmin(ans[0][2], min(need[n + 0], need[n + 3]));
    chmin(ans[1][3], min(need[n + 2], need[n + 3]));
    solve(2);
    ans[2][3] = min({need[n + 3], need[n + 0], need[n + 1]});
    solve(3);
    ans[1][2] = min({need[n + 0], need[n + 1], need[n + 2]});
    for (int i = 1; i < 4; ++i) {
        for (int j = 0; j < i; ++j) {
            ans[i][j] = ans[j][i];
        }
    }
    for (int r, c; m--;) {
        cin >> r >> c, --c;
        for (int i = 0; i < 4; ++i) {
            if (r <= ans[c][i]) {
                cout << i + 1;
            }
        }
        cout << '\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 172 ms 16200 KB Output is correct
2 Correct 177 ms 16128 KB Output is correct
3 Correct 174 ms 16076 KB Output is correct
4 Correct 176 ms 16188 KB Output is correct
5 Correct 178 ms 16076 KB Output is correct
6 Correct 175 ms 16176 KB Output is correct
7 Correct 113 ms 16116 KB Output is correct
8 Correct 112 ms 16172 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 42 ms 868 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 172 ms 16200 KB Output is correct
2 Correct 177 ms 16128 KB Output is correct
3 Correct 174 ms 16076 KB Output is correct
4 Correct 176 ms 16188 KB Output is correct
5 Correct 178 ms 16076 KB Output is correct
6 Correct 175 ms 16176 KB Output is correct
7 Correct 113 ms 16116 KB Output is correct
8 Correct 112 ms 16172 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Incorrect 42 ms 868 KB Output isn't correct
12 Halted 0 ms 0 KB -