답안 #487195

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
487195 2021-11-14T19:13:46 Z MilosMilutinovic 분수 공원 (IOI21_parks) C++17
15 / 100
772 ms 40976 KB
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;

struct ds {
    vector<int> fa;
    ds(int n) {
        fa.resize(n);
        iota(fa.begin(), fa.end(), 0);
    }
    int gfa(int x) {
        return fa[x] == x ? x : fa[x] = gfa(fa[x]);
    }
    void unite(int x, int y) {
        x = gfa(x), y = gfa(y);
        if (x == y) return;
        fa[x] = y;
    }
};

//void build(vector<int> v, vector<int> u, vector<int> a, vector<int> b) {}

int construct_roads(std::vector<int> x, std::vector<int> y) {
    if (x.size() == 1) {
        build({}, {}, {}, {});
        return 1;
    }
    int n = x.size();
    int mn = *min_element(x.begin(), x.end());
    int mx = *max_element(x.begin(), x.end());
    if (mn == 2 && mx == 2) {
        int p[n];
        for (int i = 0; i < n; i++) p[i] = i;
        sort(p, p + n, [&](int i, int j) {
            return y[i] < y[j];
        });
        for (int i = 0; i + 1 < n; i++)
            if (y[p[i]] + 2 != y[p[i + 1]])
                return 0;
        vector<int> u, v, a, b;
        for (int i = 0; i + 1 < n; i++) {
            u.push_back(p[i]);
            v.push_back(p[i + 1]);
            a.push_back(x[i] - 1);
            b.push_back(y[p[i]] + 1);
        }
        build(u, v, a, b);
        return 1;
    }
    if (mn == 2 && mx == 4) {
        map<pair<int, int>, int> id;
        for (int i = 0; i < n; i++) {
            id[{x[i], y[i]}] = i + 1;
        }
        ds d(n);
        for (int i = 0; i < n; i++) {
            if (id[{x[i] + 2, y[i]}]) {
                d.unite(i, id[{x[i] + 2, y[i]}] - 1);
            }
            if (id[{x[i], y[i] + 2}]) {
                d.unite(i, id[{x[i], y[i] + 2}] - 1);
            }
        }
        for (int i = 0; i < n; i++)
            if (d.gfa(i) != d.gfa(0))
                return 0;
        vector<int> u, v, a, b;
        for (int i = 0; i < n; i++) {
            if (id[{x[i] + 2, y[i]}]) {
                u.push_back(i);
                v.push_back(id[{x[i] + 2, y[i]}] - 1);
                a.push_back(x[i] + 1);
                b.push_back(y[i] + 1);
            }
            if (id[{x[i], y[i] + 2}]) {
                u.push_back(i);
                v.push_back(id[{x[i], y[i] + 2}] - 1);
                a.push_back(x[i] == 2 ? x[i] - 1 : x[i] + 1);
                b.push_back(y[i] + 1);
            }
        }
        build(u, v, a, b);
        return 1;
    }
}

Compilation message

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:85:1: warning: control reaches end of non-void function [-Wreturn-type]
   85 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 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 0 ms 204 KB Output is correct
9 Correct 58 ms 7112 KB Output is correct
10 Correct 5 ms 1220 KB Output is correct
11 Correct 28 ms 4036 KB Output is correct
12 Correct 7 ms 1484 KB Output is correct
13 Correct 7 ms 1100 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 54 ms 7092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 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 0 ms 204 KB Output is correct
9 Correct 58 ms 7112 KB Output is correct
10 Correct 5 ms 1220 KB Output is correct
11 Correct 28 ms 4036 KB Output is correct
12 Correct 7 ms 1484 KB Output is correct
13 Correct 7 ms 1100 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 54 ms 7092 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 288 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 765 ms 38780 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 2 ms 460 KB Output is correct
26 Correct 3 ms 588 KB Output is correct
27 Correct 3 ms 716 KB Output is correct
28 Correct 217 ms 15724 KB Output is correct
29 Correct 365 ms 23532 KB Output is correct
30 Correct 548 ms 31236 KB Output is correct
31 Correct 772 ms 38960 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 0 ms 292 KB Output is correct
34 Correct 0 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 0 ms 204 KB Output is correct
40 Correct 0 ms 204 KB Output is correct
41 Correct 0 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 3 ms 716 KB Output is correct
45 Correct 301 ms 19500 KB Output is correct
46 Correct 498 ms 27996 KB Output is correct
47 Correct 510 ms 28252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 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 0 ms 204 KB Output is correct
9 Correct 58 ms 7112 KB Output is correct
10 Correct 5 ms 1220 KB Output is correct
11 Correct 28 ms 4036 KB Output is correct
12 Correct 7 ms 1484 KB Output is correct
13 Correct 7 ms 1100 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 54 ms 7092 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 288 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 765 ms 38780 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 2 ms 460 KB Output is correct
26 Correct 3 ms 588 KB Output is correct
27 Correct 3 ms 716 KB Output is correct
28 Correct 217 ms 15724 KB Output is correct
29 Correct 365 ms 23532 KB Output is correct
30 Correct 548 ms 31236 KB Output is correct
31 Correct 772 ms 38960 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 0 ms 292 KB Output is correct
34 Correct 0 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 0 ms 204 KB Output is correct
40 Correct 0 ms 204 KB Output is correct
41 Correct 0 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 3 ms 716 KB Output is correct
45 Correct 301 ms 19500 KB Output is correct
46 Correct 498 ms 27996 KB Output is correct
47 Correct 510 ms 28252 KB Output is correct
48 Incorrect 0 ms 204 KB Tree @(5, 3) appears more than once: for edges on positions 1 and 2
49 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 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 0 ms 204 KB Output is correct
9 Correct 58 ms 7112 KB Output is correct
10 Correct 5 ms 1220 KB Output is correct
11 Correct 28 ms 4036 KB Output is correct
12 Correct 7 ms 1484 KB Output is correct
13 Correct 7 ms 1100 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 54 ms 7092 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Incorrect 629 ms 32544 KB Tree @(192371, 7633) appears more than once: for edges on positions 0 and 1
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 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 0 ms 204 KB Output is correct
9 Correct 58 ms 7112 KB Output is correct
10 Correct 5 ms 1220 KB Output is correct
11 Correct 28 ms 4036 KB Output is correct
12 Correct 7 ms 1484 KB Output is correct
13 Correct 7 ms 1100 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 54 ms 7092 KB Output is correct
17 Correct 755 ms 39056 KB Output is correct
18 Incorrect 744 ms 40976 KB Tree @(50003, 50003) appears more than once: for edges on positions 183490 and 183491
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 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 0 ms 204 KB Output is correct
9 Correct 58 ms 7112 KB Output is correct
10 Correct 5 ms 1220 KB Output is correct
11 Correct 28 ms 4036 KB Output is correct
12 Correct 7 ms 1484 KB Output is correct
13 Correct 7 ms 1100 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 54 ms 7092 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 288 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 765 ms 38780 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 2 ms 460 KB Output is correct
26 Correct 3 ms 588 KB Output is correct
27 Correct 3 ms 716 KB Output is correct
28 Correct 217 ms 15724 KB Output is correct
29 Correct 365 ms 23532 KB Output is correct
30 Correct 548 ms 31236 KB Output is correct
31 Correct 772 ms 38960 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 0 ms 292 KB Output is correct
34 Correct 0 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 0 ms 204 KB Output is correct
40 Correct 0 ms 204 KB Output is correct
41 Correct 0 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 3 ms 716 KB Output is correct
45 Correct 301 ms 19500 KB Output is correct
46 Correct 498 ms 27996 KB Output is correct
47 Correct 510 ms 28252 KB Output is correct
48 Incorrect 0 ms 204 KB Tree @(5, 3) appears more than once: for edges on positions 1 and 2
49 Halted 0 ms 0 KB -