답안 #446959

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
446959 2021-07-24T05:27:45 Z blue 분수 공원 (IOI21_parks) C++17
55 / 100
1126 ms 118468 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;










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 <= 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[P2.a];
            else return X[P1.a] < X[P2.a];
        });
    }

    // 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 15 ms 33100 KB Output is correct
2 Correct 16 ms 33096 KB Output is correct
3 Correct 16 ms 33116 KB Output is correct
4 Correct 16 ms 33112 KB Output is correct
5 Correct 16 ms 33148 KB Output is correct
6 Correct 16 ms 33100 KB Output is correct
7 Correct 16 ms 33176 KB Output is correct
8 Correct 16 ms 33116 KB Output is correct
9 Correct 310 ms 70888 KB Output is correct
10 Correct 33 ms 36992 KB Output is correct
11 Correct 130 ms 53460 KB Output is correct
12 Correct 43 ms 38792 KB Output is correct
13 Correct 54 ms 39724 KB Output is correct
14 Correct 17 ms 33296 KB Output is correct
15 Correct 17 ms 33452 KB Output is correct
16 Correct 318 ms 69580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 33100 KB Output is correct
2 Correct 16 ms 33096 KB Output is correct
3 Correct 16 ms 33116 KB Output is correct
4 Correct 16 ms 33112 KB Output is correct
5 Correct 16 ms 33148 KB Output is correct
6 Correct 16 ms 33100 KB Output is correct
7 Correct 16 ms 33176 KB Output is correct
8 Correct 16 ms 33116 KB Output is correct
9 Correct 310 ms 70888 KB Output is correct
10 Correct 33 ms 36992 KB Output is correct
11 Correct 130 ms 53460 KB Output is correct
12 Correct 43 ms 38792 KB Output is correct
13 Correct 54 ms 39724 KB Output is correct
14 Correct 17 ms 33296 KB Output is correct
15 Correct 17 ms 33452 KB Output is correct
16 Correct 318 ms 69580 KB Output is correct
17 Correct 16 ms 33152 KB Output is correct
18 Correct 16 ms 33148 KB Output is correct
19 Correct 16 ms 33112 KB Output is correct
20 Correct 15 ms 33100 KB Output is correct
21 Correct 16 ms 33100 KB Output is correct
22 Correct 16 ms 33100 KB Output is correct
23 Correct 1098 ms 115180 KB Output is correct
24 Correct 16 ms 33100 KB Output is correct
25 Correct 19 ms 33596 KB Output is correct
26 Correct 18 ms 33652 KB Output is correct
27 Correct 19 ms 33756 KB Output is correct
28 Correct 285 ms 66336 KB Output is correct
29 Correct 521 ms 81604 KB Output is correct
30 Correct 749 ms 99092 KB Output is correct
31 Correct 960 ms 114636 KB Output is correct
32 Correct 16 ms 33088 KB Output is correct
33 Correct 16 ms 33124 KB Output is correct
34 Correct 16 ms 33100 KB Output is correct
35 Correct 16 ms 33080 KB Output is correct
36 Correct 16 ms 33172 KB Output is correct
37 Correct 16 ms 33100 KB Output is correct
38 Correct 16 ms 33172 KB Output is correct
39 Correct 16 ms 33184 KB Output is correct
40 Correct 16 ms 33100 KB Output is correct
41 Correct 17 ms 33172 KB Output is correct
42 Correct 16 ms 33160 KB Output is correct
43 Correct 18 ms 33356 KB Output is correct
44 Correct 19 ms 33500 KB Output is correct
45 Correct 314 ms 69948 KB Output is correct
46 Correct 549 ms 87672 KB Output is correct
47 Correct 492 ms 87488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 33100 KB Output is correct
2 Correct 16 ms 33096 KB Output is correct
3 Correct 16 ms 33116 KB Output is correct
4 Correct 16 ms 33112 KB Output is correct
5 Correct 16 ms 33148 KB Output is correct
6 Correct 16 ms 33100 KB Output is correct
7 Correct 16 ms 33176 KB Output is correct
8 Correct 16 ms 33116 KB Output is correct
9 Correct 310 ms 70888 KB Output is correct
10 Correct 33 ms 36992 KB Output is correct
11 Correct 130 ms 53460 KB Output is correct
12 Correct 43 ms 38792 KB Output is correct
13 Correct 54 ms 39724 KB Output is correct
14 Correct 17 ms 33296 KB Output is correct
15 Correct 17 ms 33452 KB Output is correct
16 Correct 318 ms 69580 KB Output is correct
17 Correct 16 ms 33152 KB Output is correct
18 Correct 16 ms 33148 KB Output is correct
19 Correct 16 ms 33112 KB Output is correct
20 Correct 15 ms 33100 KB Output is correct
21 Correct 16 ms 33100 KB Output is correct
22 Correct 16 ms 33100 KB Output is correct
23 Correct 1098 ms 115180 KB Output is correct
24 Correct 16 ms 33100 KB Output is correct
25 Correct 19 ms 33596 KB Output is correct
26 Correct 18 ms 33652 KB Output is correct
27 Correct 19 ms 33756 KB Output is correct
28 Correct 285 ms 66336 KB Output is correct
29 Correct 521 ms 81604 KB Output is correct
30 Correct 749 ms 99092 KB Output is correct
31 Correct 960 ms 114636 KB Output is correct
32 Correct 16 ms 33088 KB Output is correct
33 Correct 16 ms 33124 KB Output is correct
34 Correct 16 ms 33100 KB Output is correct
35 Correct 16 ms 33080 KB Output is correct
36 Correct 16 ms 33172 KB Output is correct
37 Correct 16 ms 33100 KB Output is correct
38 Correct 16 ms 33172 KB Output is correct
39 Correct 16 ms 33184 KB Output is correct
40 Correct 16 ms 33100 KB Output is correct
41 Correct 17 ms 33172 KB Output is correct
42 Correct 16 ms 33160 KB Output is correct
43 Correct 18 ms 33356 KB Output is correct
44 Correct 19 ms 33500 KB Output is correct
45 Correct 314 ms 69948 KB Output is correct
46 Correct 549 ms 87672 KB Output is correct
47 Correct 492 ms 87488 KB Output is correct
48 Correct 16 ms 33100 KB Output is correct
49 Correct 16 ms 33148 KB Output is correct
50 Correct 16 ms 33068 KB Output is correct
51 Correct 16 ms 33100 KB Output is correct
52 Correct 18 ms 33100 KB Output is correct
53 Correct 16 ms 33100 KB Output is correct
54 Correct 19 ms 33180 KB Output is correct
55 Incorrect 1126 ms 116104 KB Given structure is not connected: There is no path between vertices 0 and 4195
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 33100 KB Output is correct
2 Correct 16 ms 33096 KB Output is correct
3 Correct 16 ms 33116 KB Output is correct
4 Correct 16 ms 33112 KB Output is correct
5 Correct 16 ms 33148 KB Output is correct
6 Correct 16 ms 33100 KB Output is correct
7 Correct 16 ms 33176 KB Output is correct
8 Correct 16 ms 33116 KB Output is correct
9 Correct 310 ms 70888 KB Output is correct
10 Correct 33 ms 36992 KB Output is correct
11 Correct 130 ms 53460 KB Output is correct
12 Correct 43 ms 38792 KB Output is correct
13 Correct 54 ms 39724 KB Output is correct
14 Correct 17 ms 33296 KB Output is correct
15 Correct 17 ms 33452 KB Output is correct
16 Correct 318 ms 69580 KB Output is correct
17 Correct 16 ms 33164 KB Output is correct
18 Correct 16 ms 33080 KB Output is correct
19 Correct 16 ms 33108 KB Output is correct
20 Correct 799 ms 110272 KB Output is correct
21 Correct 819 ms 108936 KB Output is correct
22 Correct 792 ms 108100 KB Output is correct
23 Correct 614 ms 96896 KB Output is correct
24 Correct 288 ms 50396 KB Output is correct
25 Correct 422 ms 59188 KB Output is correct
26 Correct 389 ms 58996 KB Output is correct
27 Correct 803 ms 103176 KB Output is correct
28 Correct 829 ms 103120 KB Output is correct
29 Correct 846 ms 103124 KB Output is correct
30 Correct 833 ms 103232 KB Output is correct
31 Correct 16 ms 33100 KB Output is correct
32 Correct 47 ms 38408 KB Output is correct
33 Correct 110 ms 41772 KB Output is correct
34 Correct 748 ms 109128 KB Output is correct
35 Correct 25 ms 34508 KB Output is correct
36 Correct 75 ms 39520 KB Output is correct
37 Correct 186 ms 46060 KB Output is correct
38 Correct 254 ms 61824 KB Output is correct
39 Correct 377 ms 71836 KB Output is correct
40 Correct 534 ms 83752 KB Output is correct
41 Correct 665 ms 93900 KB Output is correct
42 Correct 835 ms 104124 KB Output is correct
43 Correct 16 ms 33076 KB Output is correct
44 Correct 15 ms 33100 KB Output is correct
45 Correct 15 ms 33168 KB Output is correct
46 Correct 15 ms 33092 KB Output is correct
47 Correct 16 ms 33068 KB Output is correct
48 Correct 17 ms 33192 KB Output is correct
49 Correct 16 ms 33100 KB Output is correct
50 Correct 17 ms 33192 KB Output is correct
51 Correct 16 ms 33092 KB Output is correct
52 Correct 16 ms 33100 KB Output is correct
53 Correct 16 ms 33088 KB Output is correct
54 Correct 17 ms 33464 KB Output is correct
55 Correct 18 ms 33528 KB Output is correct
56 Correct 308 ms 70012 KB Output is correct
57 Correct 557 ms 87680 KB Output is correct
58 Correct 532 ms 87552 KB Output is correct
59 Correct 15 ms 33100 KB Output is correct
60 Correct 17 ms 33100 KB Output is correct
61 Correct 16 ms 33084 KB Output is correct
62 Correct 752 ms 107708 KB Output is correct
63 Correct 774 ms 107844 KB Output is correct
64 Correct 779 ms 108032 KB Output is correct
65 Correct 19 ms 33612 KB Output is correct
66 Correct 22 ms 34252 KB Output is correct
67 Correct 311 ms 68956 KB Output is correct
68 Correct 549 ms 88896 KB Output is correct
69 Correct 797 ms 105484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 33100 KB Output is correct
2 Correct 16 ms 33096 KB Output is correct
3 Correct 16 ms 33116 KB Output is correct
4 Correct 16 ms 33112 KB Output is correct
5 Correct 16 ms 33148 KB Output is correct
6 Correct 16 ms 33100 KB Output is correct
7 Correct 16 ms 33176 KB Output is correct
8 Correct 16 ms 33116 KB Output is correct
9 Correct 310 ms 70888 KB Output is correct
10 Correct 33 ms 36992 KB Output is correct
11 Correct 130 ms 53460 KB Output is correct
12 Correct 43 ms 38792 KB Output is correct
13 Correct 54 ms 39724 KB Output is correct
14 Correct 17 ms 33296 KB Output is correct
15 Correct 17 ms 33452 KB Output is correct
16 Correct 318 ms 69580 KB Output is correct
17 Correct 788 ms 109760 KB Output is correct
18 Correct 781 ms 109396 KB Output is correct
19 Correct 799 ms 110048 KB Output is correct
20 Correct 961 ms 118468 KB Output is correct
21 Correct 741 ms 100744 KB Output is correct
22 Correct 16 ms 33120 KB Output is correct
23 Correct 95 ms 45584 KB Output is correct
24 Correct 38 ms 35832 KB Output is correct
25 Correct 112 ms 42804 KB Output is correct
26 Correct 251 ms 50304 KB Output is correct
27 Correct 379 ms 73928 KB Output is correct
28 Correct 515 ms 85656 KB Output is correct
29 Correct 673 ms 95368 KB Output is correct
30 Correct 790 ms 105036 KB Output is correct
31 Correct 1008 ms 115156 KB Output is correct
32 Correct 868 ms 115796 KB Output is correct
33 Correct 755 ms 109396 KB Output is correct
34 Correct 21 ms 33844 KB Output is correct
35 Correct 24 ms 34424 KB Output is correct
36 Correct 348 ms 71752 KB Output is correct
37 Correct 602 ms 92504 KB Output is correct
38 Correct 886 ms 111216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 33100 KB Output is correct
2 Correct 16 ms 33096 KB Output is correct
3 Correct 16 ms 33116 KB Output is correct
4 Correct 16 ms 33112 KB Output is correct
5 Correct 16 ms 33148 KB Output is correct
6 Correct 16 ms 33100 KB Output is correct
7 Correct 16 ms 33176 KB Output is correct
8 Correct 16 ms 33116 KB Output is correct
9 Correct 310 ms 70888 KB Output is correct
10 Correct 33 ms 36992 KB Output is correct
11 Correct 130 ms 53460 KB Output is correct
12 Correct 43 ms 38792 KB Output is correct
13 Correct 54 ms 39724 KB Output is correct
14 Correct 17 ms 33296 KB Output is correct
15 Correct 17 ms 33452 KB Output is correct
16 Correct 318 ms 69580 KB Output is correct
17 Correct 16 ms 33152 KB Output is correct
18 Correct 16 ms 33148 KB Output is correct
19 Correct 16 ms 33112 KB Output is correct
20 Correct 15 ms 33100 KB Output is correct
21 Correct 16 ms 33100 KB Output is correct
22 Correct 16 ms 33100 KB Output is correct
23 Correct 1098 ms 115180 KB Output is correct
24 Correct 16 ms 33100 KB Output is correct
25 Correct 19 ms 33596 KB Output is correct
26 Correct 18 ms 33652 KB Output is correct
27 Correct 19 ms 33756 KB Output is correct
28 Correct 285 ms 66336 KB Output is correct
29 Correct 521 ms 81604 KB Output is correct
30 Correct 749 ms 99092 KB Output is correct
31 Correct 960 ms 114636 KB Output is correct
32 Correct 16 ms 33088 KB Output is correct
33 Correct 16 ms 33124 KB Output is correct
34 Correct 16 ms 33100 KB Output is correct
35 Correct 16 ms 33080 KB Output is correct
36 Correct 16 ms 33172 KB Output is correct
37 Correct 16 ms 33100 KB Output is correct
38 Correct 16 ms 33172 KB Output is correct
39 Correct 16 ms 33184 KB Output is correct
40 Correct 16 ms 33100 KB Output is correct
41 Correct 17 ms 33172 KB Output is correct
42 Correct 16 ms 33160 KB Output is correct
43 Correct 18 ms 33356 KB Output is correct
44 Correct 19 ms 33500 KB Output is correct
45 Correct 314 ms 69948 KB Output is correct
46 Correct 549 ms 87672 KB Output is correct
47 Correct 492 ms 87488 KB Output is correct
48 Correct 16 ms 33100 KB Output is correct
49 Correct 16 ms 33148 KB Output is correct
50 Correct 16 ms 33068 KB Output is correct
51 Correct 16 ms 33100 KB Output is correct
52 Correct 18 ms 33100 KB Output is correct
53 Correct 16 ms 33100 KB Output is correct
54 Correct 19 ms 33180 KB Output is correct
55 Incorrect 1126 ms 116104 KB Given structure is not connected: There is no path between vertices 0 and 4195
56 Halted 0 ms 0 KB -