답안 #446953

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
446953 2021-07-24T05:02:08 Z blue 분수 공원 (IOI21_parks) C++17
35 / 100
3500 ms 117780 KB
#include "parks.h"
#include <vector>
#include <set>
#include <algorithm>
#include <iostream>
using namespace std;

const int maxN = 200'000;
const int MX = 1'000'000;



vector<int> fountain_edge[maxN];
vector<int> fountain_visit(maxN, 0);
int visit_count = 0;

void fountain_dfs(int u)
{
    fountain_visit[u] = 1;
    visit_count++;
    for(int v: fountain_edge[u])
    {
        if(fountain_visit[v]) continue;
        fountain_dfs(v);
    }
}






struct point
{
    int i;
    int x;
    int y;
};

bool operator < (point A, point B)
{
    if(A.x == B.x) return A.y < B.y;
    return A.x < B.x;
};


int N;
vector<int> X, Y;
set<point> fountains;

int point_index(int x, int y)
{
    set<point>::iterator it = fountains.find(point{-1, x, y});
    if(it == fountains.end()) return -1;
    else return it->i;
}





struct path
{
    int i;
    int a;
    int b;

    path(int A, int B)
    {
        a = min(A, B);
        b = max(A, B);
    }

    path(int I, int A, int B)
    {
        i = I;
        a = min(A, B);
        b = max(A, B);
    }
};

bool operator < (path P, path Q)
{
    if(P.a == Q.a) return P.b < Q.b;
    return P.a < Q.a;
}

vector<path> temp_paths;
set<path> paths;





struct bench
{
    int i;
    int x;
    int y;
};

bool operator < (bench C, bench D)
{
    if(C.x == D.x) return C.y < D.y;
    return C.x < D.x;
}


set<bench> benches;

int bench_index(int x, int y)
{
    set<bench>::iterator it = benches.find(bench{-1, x, y});
    if(it == benches.end()) return -1;
    else return it->i;
}


vector<path>* bench_edge = new vector<path>[MX];











vector<int> bench_visit(MX, 0);

vector<int> U, V, A, B;










vector<int> parent(maxN);
vector<int> siz(maxN, 1);


int getRoot(int u)
{
    int v;
    for(v = u; parent[v] != v; v = parent[v]);
    parent[u] = v;
    return v;
}

void join(int u, int v)
{
    u = getRoot(u);
    v = getRoot(v);

    if(siz[u] < siz[v]) swap(u, v);

    parent[v] = u;
}

bool connected(int u, int v)
{
    return getRoot(u) == getRoot(v);
}








int construct_roads(vector<int> x, vector<int> y)
{
    // cerr << "check\n";
    X = x;
    Y = y;

    N = X.size();

    for(int i = 0; i < N; i++)
        fountains.insert(point{i, x[i], y[i]});







    // cerr << "check 2\n";


    for(int i = 0; i < N; i++)
    {
        int I;

        I = point_index(x[i] - 2, y[i]);
        if(I != -1)
        {
            // cerr << i << ' ' << I << '\n';

            fountain_edge[i].push_back(I);
            fountain_edge[I].push_back(i);

            temp_paths.push_back(path(i, I));

            // cerr << temp_paths.size() << '\n';
        }

        I = point_index(x[i], y[i] - 2);
        if(I != -1)
        {
            // cerr << i << ' ' << I << '\n';

            fountain_edge[i].push_back(I);
            fountain_edge[I].push_back(i);

            temp_paths.push_back(path(i, I));

            // cerr << temp_paths.size() << '\n';
        }
    }

    // cerr << temp_paths.size() << '\n';

    // cerr << "check 3\n";






    fountain_dfs(0);
    if(visit_count != N)
    {
        return 0;
    }





    int path_id = -1;
    for(path p: temp_paths)
    {
        path_id++;
            // cerr << "P -> " << path_id << ' ' << p.a <<  ' ' << p.b << '\n';
        paths.insert(path(path_id, p.a, p.b));
    }

    // cerr << "check 4\n";







    int bench_id = -1;
    for(path p: paths)
    {
        // cerr << "p = " << p.i << ' ' << p.a << ' ' << p.b << '\n';
        int x1 = X[p.a];
        int y1 = Y[p.a];

        int x2 = X[p.b];
        int y2 = Y[p.b];


        bench new_bench;

        if(x1 == x2)
        {
            if( ((x1+1) + (y1+y2)/2) % 4 == 0 )
                new_bench = bench{-1, x1+1, (y1+y2)/2};
            else
                new_bench = bench{-1, x1-1, (y1+y2)/2};
        }
        else
        {
            if( ((x1+x2)/2 + (y1+1)) % 4 == 2 )
                new_bench = bench{-1, (x1+x2)/2, y1+1};
            else
                new_bench = bench{-1, (x1+x2)/2, y1-1};
        }

        int curr_bench_index;

        // cerr << "before I\n";

        int I = bench_index(new_bench.x, new_bench.y);

        if(I == -1)
        {
            bench_id++;
            curr_bench_index = bench_id;

            new_bench.i = curr_bench_index;

            benches.insert(new_bench);
        }
        else
        {
            curr_bench_index = I;
        }

        bench_edge[curr_bench_index].push_back(p);
    }

    // cerr << "check 5\n";









    for(int i = 0; i < N; i++)
        parent[i] = i;


    for(int i = 0; i <= bench_id; i++)
    {
        sort(bench_edge[i].begin(), bench_edge[i].end(), [] (path P1, path P2)
        {
            if(X[P1.a] == X[P1.b]) return Y[P1.a] > Y[P1.b];
            else return X[P1.a] > X[P1.b];
        });
    }

    // cerr << "check 6\n";



    for(bench q: benches)
    {
        for(path z: bench_edge[q.i])
        {
            if(connected(z.a, z.b)) continue;

            U.push_back(z.a);
            V.push_back(z.b);
            A.push_back(q.x);
            B.push_back(q.y);

            join(z.a, z.b);

            break;
        }
    }

    // cerr << "check 7\n";

    build(U, V, A, B);
    return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 34636 KB Output is correct
2 Correct 25 ms 34720 KB Output is correct
3 Correct 24 ms 34756 KB Output is correct
4 Correct 24 ms 34764 KB Output is correct
5 Correct 20 ms 34636 KB Output is correct
6 Correct 20 ms 34688 KB Output is correct
7 Correct 20 ms 34764 KB Output is correct
8 Correct 21 ms 34764 KB Output is correct
9 Correct 358 ms 73272 KB Output is correct
10 Correct 38 ms 38732 KB Output is correct
11 Correct 135 ms 55508 KB Output is correct
12 Correct 47 ms 40516 KB Output is correct
13 Correct 53 ms 41688 KB Output is correct
14 Correct 19 ms 34892 KB Output is correct
15 Correct 21 ms 35020 KB Output is correct
16 Correct 371 ms 72048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 34636 KB Output is correct
2 Correct 25 ms 34720 KB Output is correct
3 Correct 24 ms 34756 KB Output is correct
4 Correct 24 ms 34764 KB Output is correct
5 Correct 20 ms 34636 KB Output is correct
6 Correct 20 ms 34688 KB Output is correct
7 Correct 20 ms 34764 KB Output is correct
8 Correct 21 ms 34764 KB Output is correct
9 Correct 358 ms 73272 KB Output is correct
10 Correct 38 ms 38732 KB Output is correct
11 Correct 135 ms 55508 KB Output is correct
12 Correct 47 ms 40516 KB Output is correct
13 Correct 53 ms 41688 KB Output is correct
14 Correct 19 ms 34892 KB Output is correct
15 Correct 21 ms 35020 KB Output is correct
16 Correct 371 ms 72048 KB Output is correct
17 Correct 20 ms 34724 KB Output is correct
18 Correct 20 ms 34672 KB Output is correct
19 Correct 20 ms 34668 KB Output is correct
20 Correct 20 ms 34768 KB Output is correct
21 Correct 20 ms 34764 KB Output is correct
22 Correct 20 ms 34764 KB Output is correct
23 Correct 1126 ms 117148 KB Output is correct
24 Correct 20 ms 34764 KB Output is correct
25 Correct 23 ms 35176 KB Output is correct
26 Correct 21 ms 35148 KB Output is correct
27 Correct 23 ms 35268 KB Output is correct
28 Correct 337 ms 68372 KB Output is correct
29 Correct 563 ms 83460 KB Output is correct
30 Correct 814 ms 101260 KB Output is correct
31 Correct 1111 ms 116648 KB Output is correct
32 Correct 19 ms 34764 KB Output is correct
33 Correct 22 ms 34708 KB Output is correct
34 Correct 20 ms 34760 KB Output is correct
35 Correct 21 ms 34752 KB Output is correct
36 Correct 20 ms 34760 KB Output is correct
37 Correct 25 ms 34744 KB Output is correct
38 Correct 20 ms 34760 KB Output is correct
39 Correct 20 ms 34764 KB Output is correct
40 Correct 19 ms 34636 KB Output is correct
41 Correct 22 ms 34652 KB Output is correct
42 Correct 20 ms 34692 KB Output is correct
43 Correct 21 ms 34996 KB Output is correct
44 Correct 22 ms 35156 KB Output is correct
45 Correct 348 ms 71876 KB Output is correct
46 Correct 584 ms 89712 KB Output is correct
47 Correct 588 ms 89496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 34636 KB Output is correct
2 Correct 25 ms 34720 KB Output is correct
3 Correct 24 ms 34756 KB Output is correct
4 Correct 24 ms 34764 KB Output is correct
5 Correct 20 ms 34636 KB Output is correct
6 Correct 20 ms 34688 KB Output is correct
7 Correct 20 ms 34764 KB Output is correct
8 Correct 21 ms 34764 KB Output is correct
9 Correct 358 ms 73272 KB Output is correct
10 Correct 38 ms 38732 KB Output is correct
11 Correct 135 ms 55508 KB Output is correct
12 Correct 47 ms 40516 KB Output is correct
13 Correct 53 ms 41688 KB Output is correct
14 Correct 19 ms 34892 KB Output is correct
15 Correct 21 ms 35020 KB Output is correct
16 Correct 371 ms 72048 KB Output is correct
17 Correct 20 ms 34724 KB Output is correct
18 Correct 20 ms 34672 KB Output is correct
19 Correct 20 ms 34668 KB Output is correct
20 Correct 20 ms 34768 KB Output is correct
21 Correct 20 ms 34764 KB Output is correct
22 Correct 20 ms 34764 KB Output is correct
23 Correct 1126 ms 117148 KB Output is correct
24 Correct 20 ms 34764 KB Output is correct
25 Correct 23 ms 35176 KB Output is correct
26 Correct 21 ms 35148 KB Output is correct
27 Correct 23 ms 35268 KB Output is correct
28 Correct 337 ms 68372 KB Output is correct
29 Correct 563 ms 83460 KB Output is correct
30 Correct 814 ms 101260 KB Output is correct
31 Correct 1111 ms 116648 KB Output is correct
32 Correct 19 ms 34764 KB Output is correct
33 Correct 22 ms 34708 KB Output is correct
34 Correct 20 ms 34760 KB Output is correct
35 Correct 21 ms 34752 KB Output is correct
36 Correct 20 ms 34760 KB Output is correct
37 Correct 25 ms 34744 KB Output is correct
38 Correct 20 ms 34760 KB Output is correct
39 Correct 20 ms 34764 KB Output is correct
40 Correct 19 ms 34636 KB Output is correct
41 Correct 22 ms 34652 KB Output is correct
42 Correct 20 ms 34692 KB Output is correct
43 Correct 21 ms 34996 KB Output is correct
44 Correct 22 ms 35156 KB Output is correct
45 Correct 348 ms 71876 KB Output is correct
46 Correct 584 ms 89712 KB Output is correct
47 Correct 588 ms 89496 KB Output is correct
48 Correct 20 ms 34636 KB Output is correct
49 Correct 20 ms 34772 KB Output is correct
50 Correct 20 ms 34716 KB Output is correct
51 Correct 21 ms 34764 KB Output is correct
52 Correct 20 ms 34656 KB Output is correct
53 Correct 22 ms 34776 KB Output is correct
54 Correct 20 ms 34716 KB Output is correct
55 Incorrect 1298 ms 117780 KB Given structure is not connected: There is no path between vertices 0 and 63
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 34636 KB Output is correct
2 Correct 25 ms 34720 KB Output is correct
3 Correct 24 ms 34756 KB Output is correct
4 Correct 24 ms 34764 KB Output is correct
5 Correct 20 ms 34636 KB Output is correct
6 Correct 20 ms 34688 KB Output is correct
7 Correct 20 ms 34764 KB Output is correct
8 Correct 21 ms 34764 KB Output is correct
9 Correct 358 ms 73272 KB Output is correct
10 Correct 38 ms 38732 KB Output is correct
11 Correct 135 ms 55508 KB Output is correct
12 Correct 47 ms 40516 KB Output is correct
13 Correct 53 ms 41688 KB Output is correct
14 Correct 19 ms 34892 KB Output is correct
15 Correct 21 ms 35020 KB Output is correct
16 Correct 371 ms 72048 KB Output is correct
17 Correct 20 ms 34696 KB Output is correct
18 Correct 19 ms 34752 KB Output is correct
19 Correct 20 ms 34744 KB Output is correct
20 Correct 899 ms 112488 KB Output is correct
21 Correct 856 ms 110924 KB Output is correct
22 Correct 867 ms 110352 KB Output is correct
23 Correct 692 ms 99068 KB Output is correct
24 Correct 309 ms 52676 KB Output is correct
25 Correct 465 ms 61304 KB Output is correct
26 Correct 405 ms 61312 KB Output is correct
27 Correct 878 ms 105196 KB Output is correct
28 Correct 850 ms 105332 KB Output is correct
29 Correct 991 ms 105236 KB Output is correct
30 Correct 874 ms 105332 KB Output is correct
31 Correct 21 ms 34764 KB Output is correct
32 Correct 53 ms 40100 KB Output is correct
33 Correct 113 ms 43968 KB Output is correct
34 Correct 824 ms 111452 KB Output is correct
35 Correct 30 ms 36172 KB Output is correct
36 Correct 79 ms 41720 KB Output is correct
37 Correct 192 ms 48328 KB Output is correct
38 Correct 278 ms 63972 KB Output is correct
39 Correct 402 ms 73908 KB Output is correct
40 Correct 554 ms 85816 KB Output is correct
41 Correct 736 ms 96020 KB Output is correct
42 Correct 888 ms 106300 KB Output is correct
43 Correct 21 ms 34636 KB Output is correct
44 Correct 20 ms 34764 KB Output is correct
45 Correct 19 ms 34708 KB Output is correct
46 Correct 20 ms 34756 KB Output is correct
47 Correct 19 ms 34764 KB Output is correct
48 Correct 19 ms 34732 KB Output is correct
49 Correct 20 ms 34748 KB Output is correct
50 Correct 20 ms 34760 KB Output is correct
51 Correct 20 ms 34764 KB Output is correct
52 Correct 20 ms 34648 KB Output is correct
53 Correct 20 ms 34696 KB Output is correct
54 Correct 21 ms 34968 KB Output is correct
55 Correct 23 ms 35160 KB Output is correct
56 Correct 343 ms 72112 KB Output is correct
57 Correct 561 ms 89920 KB Output is correct
58 Correct 574 ms 89572 KB Output is correct
59 Correct 19 ms 34764 KB Output is correct
60 Correct 20 ms 34764 KB Output is correct
61 Correct 19 ms 34756 KB Output is correct
62 Correct 801 ms 109500 KB Output is correct
63 Correct 814 ms 109624 KB Output is correct
64 Correct 797 ms 110076 KB Output is correct
65 Correct 25 ms 35276 KB Output is correct
66 Correct 27 ms 35808 KB Output is correct
67 Correct 350 ms 71032 KB Output is correct
68 Correct 603 ms 90720 KB Output is correct
69 Correct 860 ms 107348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 34636 KB Output is correct
2 Correct 25 ms 34720 KB Output is correct
3 Correct 24 ms 34756 KB Output is correct
4 Correct 24 ms 34764 KB Output is correct
5 Correct 20 ms 34636 KB Output is correct
6 Correct 20 ms 34688 KB Output is correct
7 Correct 20 ms 34764 KB Output is correct
8 Correct 21 ms 34764 KB Output is correct
9 Correct 358 ms 73272 KB Output is correct
10 Correct 38 ms 38732 KB Output is correct
11 Correct 135 ms 55508 KB Output is correct
12 Correct 47 ms 40516 KB Output is correct
13 Correct 53 ms 41688 KB Output is correct
14 Correct 19 ms 34892 KB Output is correct
15 Correct 21 ms 35020 KB Output is correct
16 Correct 371 ms 72048 KB Output is correct
17 Correct 832 ms 111732 KB Output is correct
18 Correct 884 ms 111324 KB Output is correct
19 Correct 834 ms 112112 KB Output is correct
20 Correct 1190 ms 116692 KB Output is correct
21 Correct 877 ms 101620 KB Output is correct
22 Correct 20 ms 34764 KB Output is correct
23 Correct 112 ms 47000 KB Output is correct
24 Correct 41 ms 37636 KB Output is correct
25 Correct 140 ms 44812 KB Output is correct
26 Correct 239 ms 52344 KB Output is correct
27 Correct 424 ms 74772 KB Output is correct
28 Correct 608 ms 84648 KB Output is correct
29 Correct 709 ms 95496 KB Output is correct
30 Correct 871 ms 104924 KB Output is correct
31 Correct 1080 ms 114840 KB Output is correct
32 Execution timed out 3567 ms 107556 KB Time limit exceeded
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 34636 KB Output is correct
2 Correct 25 ms 34720 KB Output is correct
3 Correct 24 ms 34756 KB Output is correct
4 Correct 24 ms 34764 KB Output is correct
5 Correct 20 ms 34636 KB Output is correct
6 Correct 20 ms 34688 KB Output is correct
7 Correct 20 ms 34764 KB Output is correct
8 Correct 21 ms 34764 KB Output is correct
9 Correct 358 ms 73272 KB Output is correct
10 Correct 38 ms 38732 KB Output is correct
11 Correct 135 ms 55508 KB Output is correct
12 Correct 47 ms 40516 KB Output is correct
13 Correct 53 ms 41688 KB Output is correct
14 Correct 19 ms 34892 KB Output is correct
15 Correct 21 ms 35020 KB Output is correct
16 Correct 371 ms 72048 KB Output is correct
17 Correct 20 ms 34724 KB Output is correct
18 Correct 20 ms 34672 KB Output is correct
19 Correct 20 ms 34668 KB Output is correct
20 Correct 20 ms 34768 KB Output is correct
21 Correct 20 ms 34764 KB Output is correct
22 Correct 20 ms 34764 KB Output is correct
23 Correct 1126 ms 117148 KB Output is correct
24 Correct 20 ms 34764 KB Output is correct
25 Correct 23 ms 35176 KB Output is correct
26 Correct 21 ms 35148 KB Output is correct
27 Correct 23 ms 35268 KB Output is correct
28 Correct 337 ms 68372 KB Output is correct
29 Correct 563 ms 83460 KB Output is correct
30 Correct 814 ms 101260 KB Output is correct
31 Correct 1111 ms 116648 KB Output is correct
32 Correct 19 ms 34764 KB Output is correct
33 Correct 22 ms 34708 KB Output is correct
34 Correct 20 ms 34760 KB Output is correct
35 Correct 21 ms 34752 KB Output is correct
36 Correct 20 ms 34760 KB Output is correct
37 Correct 25 ms 34744 KB Output is correct
38 Correct 20 ms 34760 KB Output is correct
39 Correct 20 ms 34764 KB Output is correct
40 Correct 19 ms 34636 KB Output is correct
41 Correct 22 ms 34652 KB Output is correct
42 Correct 20 ms 34692 KB Output is correct
43 Correct 21 ms 34996 KB Output is correct
44 Correct 22 ms 35156 KB Output is correct
45 Correct 348 ms 71876 KB Output is correct
46 Correct 584 ms 89712 KB Output is correct
47 Correct 588 ms 89496 KB Output is correct
48 Correct 20 ms 34636 KB Output is correct
49 Correct 20 ms 34772 KB Output is correct
50 Correct 20 ms 34716 KB Output is correct
51 Correct 21 ms 34764 KB Output is correct
52 Correct 20 ms 34656 KB Output is correct
53 Correct 22 ms 34776 KB Output is correct
54 Correct 20 ms 34716 KB Output is correct
55 Incorrect 1298 ms 117780 KB Given structure is not connected: There is no path between vertices 0 and 63
56 Halted 0 ms 0 KB -