Submission #120714

# Submission time Handle Problem Language Result Execution time Memory
120714 2019-06-25T10:09:52 Z win11905 Park (BOI16_park) C++11
100 / 100
1037 ms 25516 KB
#include <bits/stdc++.h>
#define iii tuple<int, int, int>
#define pii pair<int, int>
#define x first
#define y second
using namespace std;

const int N = 2e3+10;
const int INF = 2e9+1;

int n, m, w, h;
int par[N];
int x[N], y[N], r[N];
int d[4][4];
double eps = 1e-6;

vector<pii> g[4];

void init() {
    g[1] = {{2, 3}, {0, 2}, {2, 1}};
    g[2] = {{1, 2}, {1, 3}, {0, 2}, {0, 3}};
    g[3] = {{1, 3}, {0, 1}, {1, 2}};
}

int find(int u) { return par[u] = par[u] == u ? u : find(par[u]); }

int main() {
    init();
    iota(par, par+N, 0);
    scanf("%d %d %d %d", &n, &m, &w, &h);
    vector<iii> E;
    for(int i = 0; i < n; ++i) {
        scanf("%d %d %d", x+i, y+i, r+i);
        E.emplace_back(i, n, h - y[i] - r[i]);
        E.emplace_back(i, n + 1, x[i] - r[i]);
        E.emplace_back(i, n + 2, y[i] - r[i]);
        E.emplace_back(i, n + 3, w - x[i] - r[i]);
    }
    for(int i = 0; i < n; ++i) for(int j = i+1; j < n; ++j) {
        int dist = (int)(hypot(x[i] - x[j], y[i] - y[j]) + eps) - r[i] - r[j];
        E.emplace_back(i, j, dist);
    }
    sort(E.begin(), E.end(), [&](const iii &a, const iii &b) { return get<2>(a) < get<2>(b); });
    for(int i = 0; i < 4; ++i) for(int j = 0; j < 4; ++j) {
        if(i == j) d[i][i] = INF;
        else d[i][j] = -1;
    }
    for(auto x : E) {
        int u, v, w; tie(u, v, w) = x;
        par[find(u)] = find(v);
        for(int i = 0; i < 4; ++i) for(int j = 0; j < 4; ++j) if(i != j) {
            int dist = (j-i+4) % 4;
            for(auto z : g[dist]) {
                int a, b; tie(a, b) = z;
                a = n + ((a + i) % 4), b = n + ((b + i) % 4);
                if(find(a) == find(b) && d[i][j] == -1) d[i][j] = w;
            }
        }
    }
    for(int i = 0; i < 4; ++i) for(int j = 0; j < 4; ++j) if(d[i][j] == -1) d[i][j] = INF;
    for(int i = 0, a, b; i < m; ++i) {
        scanf("%d %d", &a, &b), b--; a *= 2;
        for(int j = 0; j < 4; ++j) if(a <= d[b][j]) printf("%d", j+1);
        printf("\n");
    }
}

Compilation message

park.cpp: In function 'int main()':
park.cpp:30: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:33:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d", x+i, y+i, r+i);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
park.cpp:62:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &a, &b), b--; a *= 2;
         ~~~~~~~~~~~~~~~~~~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 837 ms 25044 KB Output is correct
2 Correct 840 ms 25172 KB Output is correct
3 Correct 841 ms 25160 KB Output is correct
4 Correct 839 ms 25164 KB Output is correct
5 Correct 838 ms 25172 KB Output is correct
6 Correct 852 ms 25172 KB Output is correct
7 Correct 687 ms 25180 KB Output is correct
8 Correct 713 ms 25296 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 1072 KB Output is correct
2 Correct 53 ms 2164 KB Output is correct
3 Correct 53 ms 2036 KB Output is correct
4 Correct 53 ms 2160 KB Output is correct
5 Correct 53 ms 2292 KB Output is correct
6 Correct 55 ms 2164 KB Output is correct
7 Correct 42 ms 1784 KB Output is correct
8 Correct 43 ms 1788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 837 ms 25044 KB Output is correct
2 Correct 840 ms 25172 KB Output is correct
3 Correct 841 ms 25160 KB Output is correct
4 Correct 839 ms 25164 KB Output is correct
5 Correct 838 ms 25172 KB Output is correct
6 Correct 852 ms 25172 KB Output is correct
7 Correct 687 ms 25180 KB Output is correct
8 Correct 713 ms 25296 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 55 ms 1072 KB Output is correct
12 Correct 53 ms 2164 KB Output is correct
13 Correct 53 ms 2036 KB Output is correct
14 Correct 53 ms 2160 KB Output is correct
15 Correct 53 ms 2292 KB Output is correct
16 Correct 55 ms 2164 KB Output is correct
17 Correct 42 ms 1784 KB Output is correct
18 Correct 43 ms 1788 KB Output is correct
19 Correct 1037 ms 25504 KB Output is correct
20 Correct 875 ms 25468 KB Output is correct
21 Correct 891 ms 25516 KB Output is correct
22 Correct 895 ms 25388 KB Output is correct
23 Correct 877 ms 25356 KB Output is correct
24 Correct 774 ms 25488 KB Output is correct