답안 #435629

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
435629 2021-06-23T13:46:17 Z 79brue 분수 공원 (IOI21_parks) C++17
15 / 100
1342 ms 148144 KB
#include <bits/stdc++.h>
#include "parks.h"

using namespace std;

typedef long long ll;

struct Edge{
    int u, v, idx;
    Edge(){}
    Edge(int u, int v, int idx): u(u), v(v), idx(idx){}

    bool operator==(const Edge &r)const{
        return idx==r.idx;
    }
};

struct dat{
    int x, y;
    vector<Edge> vec;
    dat(){}
    dat(int x, int y, vector<Edge> vec): x(x), y(y), vec(vec){}

    bool operator<(const dat &r)const{
        if(vec.size() != r.vec.size()) return vec.size() < r.vec.size();
        return make_pair(x, y) < make_pair(r.x, r.y);
    }
};

int xx[]={1, -1, 0, 0}, yy[]={0, 0, 1, -1};

int n;
pair<int, int> arr[200002];
map<pair<int, int>, int> idx;

int par[200002];
int edgeU[200002], edgeV[200002], edgeCnt;
int edgeA[200002], edgeB[200002];
vector<pair<int, int> > link[200002];
map<pair<int, int>, vector<Edge> > mp;
set<dat> st;

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

void merge(int x, int y){
    x = find(x), y = find(y);
    par[y] = x;
}

void dfs(int u){
    int x = arr[u].first, y = arr[u].second;
    for(int d=0; d<4; d++){
        int tx = x+xx[d]+xx[d], ty = y+yy[d]+yy[d];
        if(idx.find(make_pair(tx, ty)) == idx.end()) continue;
        int tmp = idx[make_pair(tx, ty)];
        if(find(u) == find(tmp)) continue;

        edgeU[edgeCnt] = u, edgeV[edgeCnt] = tmp;
        if(x == tx){
            mp[make_pair(x+1, y+yy[d])].push_back(Edge(u, tmp, edgeCnt));
            mp[make_pair(x-1, y+yy[d])].push_back(Edge(u, tmp, edgeCnt));
            link[edgeCnt].push_back(make_pair(x+1, y+yy[d]));
            link[edgeCnt].push_back(make_pair(x-1, y+yy[d]));
        }
        else{
            mp[make_pair(x+xx[d], y+1)].push_back(Edge(u, tmp, edgeCnt));
            mp[make_pair(x+xx[d], y-1)].push_back(Edge(u, tmp, edgeCnt));
            link[edgeCnt].push_back(make_pair(x+xx[d], y-1));
            link[edgeCnt].push_back(make_pair(x+xx[d], y+1));
        }
        edgeCnt++;

        merge(u, tmp);
        dfs(tmp);
    }
}

int construct_roads(vector<int> x, vector<int> y) {
    n = (int)x.size();
    for(int i=0; i<n; i++){
        arr[i] = make_pair(x[i], y[i]);
        par[i] = i;
        idx[arr[i]] = i;
    }

    int start = min_element(arr, arr+n) - arr;
    dfs(start);
    for(int i=0; i<n; i++){
        if(find(i) != find(0)) return 0;
    }

    for(auto p: mp){
        st.insert(dat(p.first.first, p.first.second, p.second));
    }
    while(!st.empty()){
        dat tmp = *st.begin(); st.erase(st.begin());
        if(tmp.vec.empty()) continue;
        Edge edge = tmp.vec[0];
        edgeA[edge.idx] = tmp.x;
        edgeB[edge.idx] = tmp.y;
        for(auto p: link[edge.idx]){
            if(p.first == tmp.x && p.second == tmp.y) continue;
            st.erase(dat(p.first, p.second, mp[p]));
            mp[p].erase(find(mp[p].begin(), mp[p].end(), Edge(edgeU[edge.idx], edgeV[edge.idx], edge.idx)));
            st.insert(dat(p.first, p.second, mp[p]));
        }
    }

    build(vector<int>(edgeU, edgeU+n-1), vector<int>(edgeV, edgeV+n-1), vector<int>(edgeA, edgeA+n-1), vector<int>(edgeB, edgeB+n-1));
    return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4940 KB Output is correct
2 Correct 4 ms 4940 KB Output is correct
3 Correct 4 ms 4940 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 4 ms 4940 KB Output is correct
6 Correct 4 ms 4940 KB Output is correct
7 Correct 4 ms 4940 KB Output is correct
8 Correct 4 ms 4940 KB Output is correct
9 Correct 529 ms 76208 KB Output is correct
10 Correct 46 ms 12104 KB Output is correct
11 Correct 265 ms 43324 KB Output is correct
12 Correct 67 ms 15740 KB Output is correct
13 Correct 78 ms 20588 KB Output is correct
14 Correct 5 ms 5196 KB Output is correct
15 Correct 5 ms 5324 KB Output is correct
16 Correct 533 ms 76296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4940 KB Output is correct
2 Correct 4 ms 4940 KB Output is correct
3 Correct 4 ms 4940 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 4 ms 4940 KB Output is correct
6 Correct 4 ms 4940 KB Output is correct
7 Correct 4 ms 4940 KB Output is correct
8 Correct 4 ms 4940 KB Output is correct
9 Correct 529 ms 76208 KB Output is correct
10 Correct 46 ms 12104 KB Output is correct
11 Correct 265 ms 43324 KB Output is correct
12 Correct 67 ms 15740 KB Output is correct
13 Correct 78 ms 20588 KB Output is correct
14 Correct 5 ms 5196 KB Output is correct
15 Correct 5 ms 5324 KB Output is correct
16 Correct 533 ms 76296 KB Output is correct
17 Correct 4 ms 4940 KB Output is correct
18 Correct 4 ms 4940 KB Output is correct
19 Correct 4 ms 4940 KB Output is correct
20 Correct 4 ms 4940 KB Output is correct
21 Correct 4 ms 4940 KB Output is correct
22 Correct 5 ms 5068 KB Output is correct
23 Correct 1074 ms 108644 KB Output is correct
24 Correct 4 ms 4940 KB Output is correct
25 Correct 7 ms 5580 KB Output is correct
26 Correct 7 ms 5600 KB Output is correct
27 Correct 6 ms 5452 KB Output is correct
28 Correct 353 ms 46360 KB Output is correct
29 Correct 596 ms 67080 KB Output is correct
30 Correct 788 ms 88008 KB Output is correct
31 Correct 1016 ms 108704 KB Output is correct
32 Correct 4 ms 4940 KB Output is correct
33 Correct 4 ms 4940 KB Output is correct
34 Correct 4 ms 4940 KB Output is correct
35 Correct 4 ms 4940 KB Output is correct
36 Correct 4 ms 4940 KB Output is correct
37 Correct 4 ms 5000 KB Output is correct
38 Correct 4 ms 4940 KB Output is correct
39 Correct 3 ms 4940 KB Output is correct
40 Correct 4 ms 4940 KB Output is correct
41 Correct 4 ms 4940 KB Output is correct
42 Correct 4 ms 4940 KB Output is correct
43 Correct 5 ms 5452 KB Output is correct
44 Correct 6 ms 5452 KB Output is correct
45 Correct 512 ms 60164 KB Output is correct
46 Correct 745 ms 85000 KB Output is correct
47 Correct 739 ms 85072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4940 KB Output is correct
2 Correct 4 ms 4940 KB Output is correct
3 Correct 4 ms 4940 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 4 ms 4940 KB Output is correct
6 Correct 4 ms 4940 KB Output is correct
7 Correct 4 ms 4940 KB Output is correct
8 Correct 4 ms 4940 KB Output is correct
9 Correct 529 ms 76208 KB Output is correct
10 Correct 46 ms 12104 KB Output is correct
11 Correct 265 ms 43324 KB Output is correct
12 Correct 67 ms 15740 KB Output is correct
13 Correct 78 ms 20588 KB Output is correct
14 Correct 5 ms 5196 KB Output is correct
15 Correct 5 ms 5324 KB Output is correct
16 Correct 533 ms 76296 KB Output is correct
17 Correct 4 ms 4940 KB Output is correct
18 Correct 4 ms 4940 KB Output is correct
19 Correct 4 ms 4940 KB Output is correct
20 Correct 4 ms 4940 KB Output is correct
21 Correct 4 ms 4940 KB Output is correct
22 Correct 5 ms 5068 KB Output is correct
23 Correct 1074 ms 108644 KB Output is correct
24 Correct 4 ms 4940 KB Output is correct
25 Correct 7 ms 5580 KB Output is correct
26 Correct 7 ms 5600 KB Output is correct
27 Correct 6 ms 5452 KB Output is correct
28 Correct 353 ms 46360 KB Output is correct
29 Correct 596 ms 67080 KB Output is correct
30 Correct 788 ms 88008 KB Output is correct
31 Correct 1016 ms 108704 KB Output is correct
32 Correct 4 ms 4940 KB Output is correct
33 Correct 4 ms 4940 KB Output is correct
34 Correct 4 ms 4940 KB Output is correct
35 Correct 4 ms 4940 KB Output is correct
36 Correct 4 ms 4940 KB Output is correct
37 Correct 4 ms 5000 KB Output is correct
38 Correct 4 ms 4940 KB Output is correct
39 Correct 3 ms 4940 KB Output is correct
40 Correct 4 ms 4940 KB Output is correct
41 Correct 4 ms 4940 KB Output is correct
42 Correct 4 ms 4940 KB Output is correct
43 Correct 5 ms 5452 KB Output is correct
44 Correct 6 ms 5452 KB Output is correct
45 Correct 512 ms 60164 KB Output is correct
46 Correct 745 ms 85000 KB Output is correct
47 Correct 739 ms 85072 KB Output is correct
48 Correct 4 ms 4940 KB Output is correct
49 Correct 5 ms 4940 KB Output is correct
50 Correct 4 ms 4940 KB Output is correct
51 Correct 4 ms 4940 KB Output is correct
52 Correct 4 ms 4940 KB Output is correct
53 Correct 4 ms 4940 KB Output is correct
54 Correct 4 ms 4940 KB Output is correct
55 Correct 1121 ms 107140 KB Output is correct
56 Correct 4 ms 4940 KB Output is correct
57 Correct 9 ms 5836 KB Output is correct
58 Correct 26 ms 8096 KB Output is correct
59 Correct 11 ms 6348 KB Output is correct
60 Correct 493 ms 55856 KB Output is correct
61 Correct 665 ms 73744 KB Output is correct
62 Correct 872 ms 89236 KB Output is correct
63 Correct 1085 ms 107176 KB Output is correct
64 Correct 4 ms 4940 KB Output is correct
65 Correct 4 ms 4964 KB Output is correct
66 Correct 4 ms 4940 KB Output is correct
67 Correct 1223 ms 147720 KB Output is correct
68 Correct 1203 ms 135280 KB Output is correct
69 Correct 1130 ms 140812 KB Output is correct
70 Correct 10 ms 5836 KB Output is correct
71 Correct 14 ms 6220 KB Output is correct
72 Runtime error 497 ms 112048 KB Execution killed with signal 11
73 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4940 KB Output is correct
2 Correct 4 ms 4940 KB Output is correct
3 Correct 4 ms 4940 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 4 ms 4940 KB Output is correct
6 Correct 4 ms 4940 KB Output is correct
7 Correct 4 ms 4940 KB Output is correct
8 Correct 4 ms 4940 KB Output is correct
9 Correct 529 ms 76208 KB Output is correct
10 Correct 46 ms 12104 KB Output is correct
11 Correct 265 ms 43324 KB Output is correct
12 Correct 67 ms 15740 KB Output is correct
13 Correct 78 ms 20588 KB Output is correct
14 Correct 5 ms 5196 KB Output is correct
15 Correct 5 ms 5324 KB Output is correct
16 Correct 533 ms 76296 KB Output is correct
17 Correct 4 ms 4940 KB Output is correct
18 Correct 4 ms 4940 KB Output is correct
19 Correct 4 ms 4940 KB Output is correct
20 Correct 1010 ms 104812 KB Output is correct
21 Correct 945 ms 92056 KB Output is correct
22 Correct 1046 ms 104536 KB Output is correct
23 Correct 916 ms 121604 KB Output is correct
24 Correct 218 ms 22900 KB Output is correct
25 Correct 238 ms 23064 KB Output is correct
26 Correct 220 ms 23068 KB Output is correct
27 Correct 968 ms 122772 KB Output is correct
28 Correct 986 ms 122716 KB Output is correct
29 Correct 1342 ms 122688 KB Output is correct
30 Correct 1288 ms 122732 KB Output is correct
31 Correct 4 ms 4940 KB Output is correct
32 Runtime error 81 ms 23320 KB Execution killed with signal 11
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4940 KB Output is correct
2 Correct 4 ms 4940 KB Output is correct
3 Correct 4 ms 4940 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 4 ms 4940 KB Output is correct
6 Correct 4 ms 4940 KB Output is correct
7 Correct 4 ms 4940 KB Output is correct
8 Correct 4 ms 4940 KB Output is correct
9 Correct 529 ms 76208 KB Output is correct
10 Correct 46 ms 12104 KB Output is correct
11 Correct 265 ms 43324 KB Output is correct
12 Correct 67 ms 15740 KB Output is correct
13 Correct 78 ms 20588 KB Output is correct
14 Correct 5 ms 5196 KB Output is correct
15 Correct 5 ms 5324 KB Output is correct
16 Correct 533 ms 76296 KB Output is correct
17 Correct 1128 ms 148144 KB Output is correct
18 Correct 1230 ms 141972 KB Output is correct
19 Correct 1012 ms 104576 KB Output is correct
20 Correct 1194 ms 108108 KB Output is correct
21 Correct 1090 ms 111868 KB Output is correct
22 Correct 4 ms 4940 KB Output is correct
23 Runtime error 161 ms 37836 KB Execution killed with signal 11
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4940 KB Output is correct
2 Correct 4 ms 4940 KB Output is correct
3 Correct 4 ms 4940 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 4 ms 4940 KB Output is correct
6 Correct 4 ms 4940 KB Output is correct
7 Correct 4 ms 4940 KB Output is correct
8 Correct 4 ms 4940 KB Output is correct
9 Correct 529 ms 76208 KB Output is correct
10 Correct 46 ms 12104 KB Output is correct
11 Correct 265 ms 43324 KB Output is correct
12 Correct 67 ms 15740 KB Output is correct
13 Correct 78 ms 20588 KB Output is correct
14 Correct 5 ms 5196 KB Output is correct
15 Correct 5 ms 5324 KB Output is correct
16 Correct 533 ms 76296 KB Output is correct
17 Correct 4 ms 4940 KB Output is correct
18 Correct 4 ms 4940 KB Output is correct
19 Correct 4 ms 4940 KB Output is correct
20 Correct 4 ms 4940 KB Output is correct
21 Correct 4 ms 4940 KB Output is correct
22 Correct 5 ms 5068 KB Output is correct
23 Correct 1074 ms 108644 KB Output is correct
24 Correct 4 ms 4940 KB Output is correct
25 Correct 7 ms 5580 KB Output is correct
26 Correct 7 ms 5600 KB Output is correct
27 Correct 6 ms 5452 KB Output is correct
28 Correct 353 ms 46360 KB Output is correct
29 Correct 596 ms 67080 KB Output is correct
30 Correct 788 ms 88008 KB Output is correct
31 Correct 1016 ms 108704 KB Output is correct
32 Correct 4 ms 4940 KB Output is correct
33 Correct 4 ms 4940 KB Output is correct
34 Correct 4 ms 4940 KB Output is correct
35 Correct 4 ms 4940 KB Output is correct
36 Correct 4 ms 4940 KB Output is correct
37 Correct 4 ms 5000 KB Output is correct
38 Correct 4 ms 4940 KB Output is correct
39 Correct 3 ms 4940 KB Output is correct
40 Correct 4 ms 4940 KB Output is correct
41 Correct 4 ms 4940 KB Output is correct
42 Correct 4 ms 4940 KB Output is correct
43 Correct 5 ms 5452 KB Output is correct
44 Correct 6 ms 5452 KB Output is correct
45 Correct 512 ms 60164 KB Output is correct
46 Correct 745 ms 85000 KB Output is correct
47 Correct 739 ms 85072 KB Output is correct
48 Correct 4 ms 4940 KB Output is correct
49 Correct 5 ms 4940 KB Output is correct
50 Correct 4 ms 4940 KB Output is correct
51 Correct 4 ms 4940 KB Output is correct
52 Correct 4 ms 4940 KB Output is correct
53 Correct 4 ms 4940 KB Output is correct
54 Correct 4 ms 4940 KB Output is correct
55 Correct 1121 ms 107140 KB Output is correct
56 Correct 4 ms 4940 KB Output is correct
57 Correct 9 ms 5836 KB Output is correct
58 Correct 26 ms 8096 KB Output is correct
59 Correct 11 ms 6348 KB Output is correct
60 Correct 493 ms 55856 KB Output is correct
61 Correct 665 ms 73744 KB Output is correct
62 Correct 872 ms 89236 KB Output is correct
63 Correct 1085 ms 107176 KB Output is correct
64 Correct 4 ms 4940 KB Output is correct
65 Correct 4 ms 4964 KB Output is correct
66 Correct 4 ms 4940 KB Output is correct
67 Correct 1223 ms 147720 KB Output is correct
68 Correct 1203 ms 135280 KB Output is correct
69 Correct 1130 ms 140812 KB Output is correct
70 Correct 10 ms 5836 KB Output is correct
71 Correct 14 ms 6220 KB Output is correct
72 Runtime error 497 ms 112048 KB Execution killed with signal 11
73 Halted 0 ms 0 KB -