답안 #1021050

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1021050 2024-07-12T13:18:14 Z Blistering_Barnacles 분수 공원 (IOI21_parks) C++17
30 / 100
745 ms 64952 KB
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
int construct_roads(vector<int> x, vector<int> y) {
    if (x.size() == 1) {
    build({}, {}, {}, {});
        return 1;
    }
    map<pair<int, int>, int> mp;
    vector<int> u, v, a, b;
    vector<pair<int, int>> e;
    int n = (int)x.size();
    for(int i = 0; i < n; i++){
        if(mp.count({x[i], y[i] - 2})){
            e.push_back({mp[{x[i], y[i] - 2}], i});
        }
        if(mp.count({x[i], y[i] + 2})){
            e.push_back({mp[{x[i], y[i] + 2}], i});
        }
        if(mp.count({x[i] - 2, y[i]})){
            e.push_back({mp[{x[i] - 2, y[i]}], i});
        }
        if(mp.count({x[i] + 2, y[i]})){
            e.push_back({mp[{x[i] + 2, y[i]}], i});
        }
        mp[{x[i], y[i]}] = i;
    }
    vector<int> par(n, -1);
    function<int(int)> getpar = [&](int x){
        return (par[x] < 0 ? x : par[x] = getpar(par[x]));
    };
    auto mrg = [&](int x, int y){
        x = getpar(x), y = getpar(y);
        if(x == y)return false;
        if(par[x] > par[y])swap(x, y);
        par[x] += par[y], par[y] = x;
        return true;
    };
    auto cmp = [&](pair<int, int> a, pair<int, int> b){
        auto [i1, j1] = a;
        auto [i2, j2] = b;
        if(x[i1] == x[j1]){
            if(x[i2] == x[j2]){
                return x[i1] < x[i2];
            }
            else{
                return x[i1] < max(x[i2], x[j2]);
            }
        }
        else{
            if(x[i2] == x[j2]){
                return min(x[i1], x[j1]) < x[i2];
            }
            else{
                return min(x[i1], x[j1]) < min(x[i2], x[j2]);
            }
        }
    };
    auto cmp2 = [&](pair<int, int> a, pair<int, int> b){
        auto [i1, j1] = a;
        auto [i2, j2] = b;
        if(x[i1] == x[j1]){
            if(x[i2] == x[j2]){
                return x[i1] < x[i2];
            }
            else{
                return true;
            }
        }
        else{
            if(x[i2] == x[j2]){
                return false;
            }
            else{
                return min(x[i1], x[j1]) < min(x[i2], x[j2]);
            }
        }
    };
    auto op = e;
    sort(op.begin(), op.end(), cmp2);
    sort(e.begin(), e.end(), cmp);
    map<pair<int, int>, bool> vis;
    map<pair<int, int>, bool> tmp;
    for(auto [i, j]: op){
        tmp[{i, j}] = mrg(i, j);
    }
    for(auto [i, j]: e){
        if(tmp[{i, j}]){
            u.push_back(i), v.push_back(j);
            if(x[i] == x[j]){
                if(!vis.count({x[i] - 1, max(y[i], y[j]) - 1})){
                    vis[{x[i] - 1, max(y[i], y[j]) - 1}] = 1;
                    a.push_back(x[i] - 1);
                    b.push_back(max(y[i], y[j]) - 1);
                }
                else{
                    vis[{x[i] + 1, max(y[i], y[j]) - 1}] = 1;
                    a.push_back(x[i] + 1);
                    b.push_back(max(y[i], y[j]) - 1);
                }
            }
            else{
                if(!vis.count({max(x[i], x[j]) - 1, y[i] - 1})){
                    vis[{max(x[i], x[j]) - 1, y[i] - 1}] = 1;
                    a.push_back(max(x[i], x[j]) - 1);
                    b.push_back(y[i] - 1);
                }
                else{
                    vis[{max(x[i], x[j]) - 1, y[i] + 1}] = 1;
                    a.push_back(max(x[i], x[j]) - 1);
                    b.push_back(y[i] + 1);
                }
            }
        }
    }
    int cnt = 0;
    for(int i = 0; i < n; i++)cnt += par[i] < 0;
    if(cnt > 1)return 0;
    build(u, v, a, b);
    return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 212 ms 27588 KB Output is correct
10 Correct 11 ms 3164 KB Output is correct
11 Correct 71 ms 14916 KB Output is correct
12 Correct 17 ms 4580 KB Output is correct
13 Correct 47 ms 10964 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 231 ms 27388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 212 ms 27588 KB Output is correct
10 Correct 11 ms 3164 KB Output is correct
11 Correct 71 ms 14916 KB Output is correct
12 Correct 17 ms 4580 KB Output is correct
13 Correct 47 ms 10964 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 231 ms 27388 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 745 ms 62516 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 2 ms 600 KB Output is correct
26 Correct 7 ms 1116 KB Output is correct
27 Correct 6 ms 1372 KB Output is correct
28 Correct 201 ms 25144 KB Output is correct
29 Correct 403 ms 37572 KB Output is correct
30 Correct 481 ms 50252 KB Output is correct
31 Correct 691 ms 62356 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 3 ms 860 KB Output is correct
44 Correct 4 ms 1112 KB Output is correct
45 Correct 226 ms 27388 KB Output is correct
46 Correct 391 ms 40236 KB Output is correct
47 Correct 361 ms 40128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 212 ms 27588 KB Output is correct
10 Correct 11 ms 3164 KB Output is correct
11 Correct 71 ms 14916 KB Output is correct
12 Correct 17 ms 4580 KB Output is correct
13 Correct 47 ms 10964 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 231 ms 27388 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 745 ms 62516 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 2 ms 600 KB Output is correct
26 Correct 7 ms 1116 KB Output is correct
27 Correct 6 ms 1372 KB Output is correct
28 Correct 201 ms 25144 KB Output is correct
29 Correct 403 ms 37572 KB Output is correct
30 Correct 481 ms 50252 KB Output is correct
31 Correct 691 ms 62356 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 3 ms 860 KB Output is correct
44 Correct 4 ms 1112 KB Output is correct
45 Correct 226 ms 27388 KB Output is correct
46 Correct 391 ms 40236 KB Output is correct
47 Correct 361 ms 40128 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 344 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 723 ms 64904 KB Output is correct
56 Correct 1 ms 344 KB Output is correct
57 Correct 3 ms 860 KB Output is correct
58 Correct 11 ms 2396 KB Output is correct
59 Correct 18 ms 3288 KB Output is correct
60 Correct 287 ms 32668 KB Output is correct
61 Correct 438 ms 44992 KB Output is correct
62 Correct 574 ms 53948 KB Output is correct
63 Correct 739 ms 64952 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 471 ms 54500 KB Output is correct
68 Correct 468 ms 54720 KB Output is correct
69 Correct 473 ms 54208 KB Output is correct
70 Correct 6 ms 1368 KB Output is correct
71 Correct 11 ms 2396 KB Output is correct
72 Correct 231 ms 28300 KB Output is correct
73 Correct 379 ms 41920 KB Output is correct
74 Correct 588 ms 55596 KB Output is correct
75 Correct 581 ms 58860 KB Output is correct
76 Correct 474 ms 55564 KB Output is correct
77 Correct 7 ms 1628 KB Output is correct
78 Correct 13 ms 2652 KB Output is correct
79 Correct 246 ms 29128 KB Output is correct
80 Correct 395 ms 43580 KB Output is correct
81 Correct 572 ms 57284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 212 ms 27588 KB Output is correct
10 Correct 11 ms 3164 KB Output is correct
11 Correct 71 ms 14916 KB Output is correct
12 Correct 17 ms 4580 KB Output is correct
13 Correct 47 ms 10964 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 231 ms 27388 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 541 ms 56508 KB Output is correct
21 Correct 485 ms 57184 KB Output is correct
22 Correct 481 ms 57208 KB Output is correct
23 Correct 451 ms 48404 KB Output is correct
24 Correct 199 ms 18520 KB Output is correct
25 Correct 508 ms 49864 KB Output is correct
26 Correct 488 ms 49860 KB Output is correct
27 Correct 496 ms 56124 KB Output is correct
28 Correct 551 ms 56516 KB Output is correct
29 Correct 531 ms 56260 KB Output is correct
30 Correct 552 ms 56256 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Incorrect 27 ms 4488 KB Tree @(185725, 20413) appears more than once: for edges on positions 637 and 656
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 212 ms 27588 KB Output is correct
10 Correct 11 ms 3164 KB Output is correct
11 Correct 71 ms 14916 KB Output is correct
12 Correct 17 ms 4580 KB Output is correct
13 Correct 47 ms 10964 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 231 ms 27388 KB Output is correct
17 Correct 505 ms 55828 KB Output is correct
18 Correct 483 ms 56796 KB Output is correct
19 Correct 539 ms 57180 KB Output is correct
20 Correct 633 ms 60096 KB Output is correct
21 Correct 534 ms 50884 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Incorrect 66 ms 9516 KB Tree @(185191, 20673) appears more than once: for edges on positions 1200 and 1220
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 212 ms 27588 KB Output is correct
10 Correct 11 ms 3164 KB Output is correct
11 Correct 71 ms 14916 KB Output is correct
12 Correct 17 ms 4580 KB Output is correct
13 Correct 47 ms 10964 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 231 ms 27388 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 745 ms 62516 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 2 ms 600 KB Output is correct
26 Correct 7 ms 1116 KB Output is correct
27 Correct 6 ms 1372 KB Output is correct
28 Correct 201 ms 25144 KB Output is correct
29 Correct 403 ms 37572 KB Output is correct
30 Correct 481 ms 50252 KB Output is correct
31 Correct 691 ms 62356 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 3 ms 860 KB Output is correct
44 Correct 4 ms 1112 KB Output is correct
45 Correct 226 ms 27388 KB Output is correct
46 Correct 391 ms 40236 KB Output is correct
47 Correct 361 ms 40128 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 344 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 723 ms 64904 KB Output is correct
56 Correct 1 ms 344 KB Output is correct
57 Correct 3 ms 860 KB Output is correct
58 Correct 11 ms 2396 KB Output is correct
59 Correct 18 ms 3288 KB Output is correct
60 Correct 287 ms 32668 KB Output is correct
61 Correct 438 ms 44992 KB Output is correct
62 Correct 574 ms 53948 KB Output is correct
63 Correct 739 ms 64952 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 471 ms 54500 KB Output is correct
68 Correct 468 ms 54720 KB Output is correct
69 Correct 473 ms 54208 KB Output is correct
70 Correct 6 ms 1368 KB Output is correct
71 Correct 11 ms 2396 KB Output is correct
72 Correct 231 ms 28300 KB Output is correct
73 Correct 379 ms 41920 KB Output is correct
74 Correct 588 ms 55596 KB Output is correct
75 Correct 581 ms 58860 KB Output is correct
76 Correct 474 ms 55564 KB Output is correct
77 Correct 7 ms 1628 KB Output is correct
78 Correct 13 ms 2652 KB Output is correct
79 Correct 246 ms 29128 KB Output is correct
80 Correct 395 ms 43580 KB Output is correct
81 Correct 572 ms 57284 KB Output is correct
82 Correct 0 ms 344 KB Output is correct
83 Correct 1 ms 348 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 541 ms 56508 KB Output is correct
86 Correct 485 ms 57184 KB Output is correct
87 Correct 481 ms 57208 KB Output is correct
88 Correct 451 ms 48404 KB Output is correct
89 Correct 199 ms 18520 KB Output is correct
90 Correct 508 ms 49864 KB Output is correct
91 Correct 488 ms 49860 KB Output is correct
92 Correct 496 ms 56124 KB Output is correct
93 Correct 551 ms 56516 KB Output is correct
94 Correct 531 ms 56260 KB Output is correct
95 Correct 552 ms 56256 KB Output is correct
96 Correct 0 ms 348 KB Output is correct
97 Incorrect 27 ms 4488 KB Tree @(185725, 20413) appears more than once: for edges on positions 637 and 656
98 Halted 0 ms 0 KB -