답안 #492420

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
492420 2021-12-07T08:37:20 Z dxz05 분수 공원 (IOI21_parks) C++17
15 / 100
611 ms 28276 KB
#include "parks.h"
#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 3e2;

int p[N];

int find(int x){
    return (x == p[x] ? x : p[x] = find(p[x]));
}

bool unite(int x, int y){
    x = find(x);
    y = find(y);
    if (x == y) return false;
    if (rand() & 1) swap(x, y);
    p[x] = y;
    return true;
}

int construct_roads(vector<int> x, vector<int> y) {
    int n = x.size();
    if (n == 1) {
        build({}, {}, {}, {});
        return 1;
    }

    iota(p, p + n, 0);

    map<pair<int, int>, int> id;
    for (int i = 0; i < n; i++){
        id[{x[i], y[i]}] = i;
    }

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

    vector<int> dx = {2, 0, -2, 0};
    vector<int> dy = {0, 2, 0, -2};

    for (int i = 0; i < n; i++){
        for (int it = 0; it < 4; it++){
            int X = x[i] + dx[it], Y = y[i] + dy[it];
            if (id.find({X, Y}) != id.end()){
                int j = id[{X, Y}];
                if (!unite(i, j)) continue;
                U.push_back(i);
                V.push_back(j);
            }
        }
    }

    if (U.size() != n - 1) return 0;

    for (int it = 0; it < n - 1; it++){
        int i = U[it], j = V[it];
        if (y[i] == y[j]){
            A.push_back((x[i] + x[j]) / 2);
            B.push_back(y[i] + 1);
        } else {
            A.push_back((x[i] == 2 ? 1 : 5));
            B.push_back((y[i] + y[j]) / 2);
        }
    }

    build(U, V, A, B);

    return 1;
}

Compilation message

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:54:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   54 |     if (U.size() != n - 1) return 0;
      |         ~~~~~~~~~^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 292 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 191 ms 14136 KB Output is correct
10 Correct 10 ms 1740 KB Output is correct
11 Correct 70 ms 7684 KB Output is correct
12 Correct 19 ms 2568 KB Output is correct
13 Correct 46 ms 4744 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 187 ms 14144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 292 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 191 ms 14136 KB Output is correct
10 Correct 10 ms 1740 KB Output is correct
11 Correct 70 ms 7684 KB Output is correct
12 Correct 19 ms 2568 KB Output is correct
13 Correct 46 ms 4744 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 187 ms 14144 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 296 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 581 ms 27972 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 2 ms 460 KB Output is correct
26 Correct 4 ms 568 KB Output is correct
27 Correct 6 ms 588 KB Output is correct
28 Correct 162 ms 11400 KB Output is correct
29 Correct 312 ms 16960 KB Output is correct
30 Correct 446 ms 22436 KB Output is correct
31 Correct 611 ms 27896 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 0 ms 204 KB Output is correct
37 Correct 0 ms 204 KB Output is correct
38 Correct 0 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
41 Correct 1 ms 204 KB Output is correct
42 Correct 0 ms 204 KB Output is correct
43 Correct 2 ms 460 KB Output is correct
44 Correct 5 ms 588 KB Output is correct
45 Correct 254 ms 14112 KB Output is correct
46 Correct 360 ms 20484 KB Output is correct
47 Correct 341 ms 20512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 292 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 191 ms 14136 KB Output is correct
10 Correct 10 ms 1740 KB Output is correct
11 Correct 70 ms 7684 KB Output is correct
12 Correct 19 ms 2568 KB Output is correct
13 Correct 46 ms 4744 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 187 ms 14144 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 296 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 581 ms 27972 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 2 ms 460 KB Output is correct
26 Correct 4 ms 568 KB Output is correct
27 Correct 6 ms 588 KB Output is correct
28 Correct 162 ms 11400 KB Output is correct
29 Correct 312 ms 16960 KB Output is correct
30 Correct 446 ms 22436 KB Output is correct
31 Correct 611 ms 27896 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 0 ms 204 KB Output is correct
37 Correct 0 ms 204 KB Output is correct
38 Correct 0 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
41 Correct 1 ms 204 KB Output is correct
42 Correct 0 ms 204 KB Output is correct
43 Correct 2 ms 460 KB Output is correct
44 Correct 5 ms 588 KB Output is correct
45 Correct 254 ms 14112 KB Output is correct
46 Correct 360 ms 20484 KB Output is correct
47 Correct 341 ms 20512 KB Output is correct
48 Incorrect 1 ms 204 KB Tree @(5, 3) appears more than once: for edges on positions 0 and 1
49 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 292 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 191 ms 14136 KB Output is correct
10 Correct 10 ms 1740 KB Output is correct
11 Correct 70 ms 7684 KB Output is correct
12 Correct 19 ms 2568 KB Output is correct
13 Correct 46 ms 4744 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 187 ms 14144 KB Output is correct
17 Incorrect 0 ms 204 KB Tree (a[0], b[0]) = (5, 3) is not adjacent to edge between u[0]=0 @(200000, 2) and v[0]=1 @(200000, 4)
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 292 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 191 ms 14136 KB Output is correct
10 Correct 10 ms 1740 KB Output is correct
11 Correct 70 ms 7684 KB Output is correct
12 Correct 19 ms 2568 KB Output is correct
13 Correct 46 ms 4744 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 187 ms 14144 KB Output is correct
17 Incorrect 546 ms 28276 KB Tree (a[2], b[2]) = (5, 52499) is not adjacent to edge between u[2]=1 @(100002, 52498) and v[2]=117727 @(100002, 52500)
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 292 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 191 ms 14136 KB Output is correct
10 Correct 10 ms 1740 KB Output is correct
11 Correct 70 ms 7684 KB Output is correct
12 Correct 19 ms 2568 KB Output is correct
13 Correct 46 ms 4744 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 187 ms 14144 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 296 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 581 ms 27972 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 2 ms 460 KB Output is correct
26 Correct 4 ms 568 KB Output is correct
27 Correct 6 ms 588 KB Output is correct
28 Correct 162 ms 11400 KB Output is correct
29 Correct 312 ms 16960 KB Output is correct
30 Correct 446 ms 22436 KB Output is correct
31 Correct 611 ms 27896 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 0 ms 204 KB Output is correct
37 Correct 0 ms 204 KB Output is correct
38 Correct 0 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
41 Correct 1 ms 204 KB Output is correct
42 Correct 0 ms 204 KB Output is correct
43 Correct 2 ms 460 KB Output is correct
44 Correct 5 ms 588 KB Output is correct
45 Correct 254 ms 14112 KB Output is correct
46 Correct 360 ms 20484 KB Output is correct
47 Correct 341 ms 20512 KB Output is correct
48 Incorrect 1 ms 204 KB Tree @(5, 3) appears more than once: for edges on positions 0 and 1
49 Halted 0 ms 0 KB -