Submission #1026322

# Submission time Handle Problem Language Result Execution time Memory
1026322 2024-07-17T22:33:57 Z HappyCapybara Fountain Parks (IOI21_parks) C++17
15 / 100
190 ms 48804 KB
#include "parks.h"
#include<bits/stdc++.h>
using namespace std;

vector<int> p;

int find(int a){
    if (p[a] == a) return a;
    else return p[a] = find(p[a]);
}

void merge(int a, int b){
    a = find(a);
    b = find(b);
    if (a == b) return;
    p[a] = b;
}

int construct_roads(vector<int> x, vector<int> y) {
    int n = x.size();
    int mx = 0;
    unordered_map<int,vector<pair<int,int>>> r, c;
    for (int i=0; i<n; i++){
        mx = max(mx, x[i]);
        r[y[i]].push_back({x[i], i});
        c[x[i]].push_back({y[i], i});
    }
    vector<pair<int,int>> el;
    //cout << "a\n";
    for (int i=2; i<=200000; i++){
        if (c[i].size() > 1){
            sort(c[i].begin(), c[i].end());
            for (int j=0; j<c[i].size()-1; j++){
                if (c[i][j+1].first-c[i][j].first == 2) el.push_back({c[i][j].second, c[i][j+1].second});
            }
        }
        if (r[i].size() > 1){
            sort(r[i].begin(), r[i].end());
            for (int j=0; j<r[i].size()-1; j++){
                if (r[i][j+1].first-r[i][j].first == 2) el.push_back({r[i][j].second, r[i][j+1].second});
            }
        }
    }
    p.resize(n);
    for (int i=0; i<n; i++) p[i] = i;
    //cout << "b\n";
    vector<int> u, v, a, b;
    int done = 0;
    int cur = -1;
    while (done < n-1){
        cur++;
        //cout << cur << " " << done << "\n";
        if (cur == el.size()) return 0;
        if (find(el[cur].first) == find(el[cur].second)) continue;
        //cout << "a\n";
        merge(el[cur].first, el[cur].second);
        done++;
        u.push_back(el[cur].first);
        v.push_back(el[cur].second);
        //cout << "b\n";
        if (x[el[cur].first] == x[el[cur].second]){
            b.push_back((y[el[cur].first]+y[el[cur].second])/2);
            if (x[el[cur].first] == 2) a.push_back(1);
            else if (x[el[cur].first] == mx) a.push_back(x[el[cur].first]+1);
            else {
                if (min(y[el[cur].first], y[el[cur].second]) % 4) a.push_back(x[el[cur].first]-1);
                else a.push_back(x[el[cur].first]+1);
            }
        }
        else {
            a.push_back((x[el[cur].first]+x[el[cur].second])/2);
            if (mx == 4) b.push_back(y[el[cur].first]-1);
            else {
                if (min(x[el[cur].first], x[el[cur].second]) % 4) b.push_back(y[el[cur].first]+1);
                else b.push_back(y[el[cur].first]-1);
            }
        }
        //cout << "c\n";
    }
    //cout << "c\n";
    build(u, v, a, b);
    return 1;
}

Compilation message

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:33:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |             for (int j=0; j<c[i].size()-1; j++){
      |                           ~^~~~~~~~~~~~~~
parks.cpp:39:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |             for (int j=0; j<r[i].size()-1; j++){
      |                           ~^~~~~~~~~~~~~~
parks.cpp:53:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         if (cur == el.size()) return 0;
      |             ~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 29 ms 24488 KB Output is correct
2 Correct 46 ms 24620 KB Output is correct
3 Correct 26 ms 24496 KB Output is correct
4 Correct 30 ms 24496 KB Output is correct
5 Correct 26 ms 24496 KB Output is correct
6 Correct 24 ms 24496 KB Output is correct
7 Correct 25 ms 24500 KB Output is correct
8 Correct 26 ms 24652 KB Output is correct
9 Correct 95 ms 36264 KB Output is correct
10 Correct 30 ms 25888 KB Output is correct
11 Correct 49 ms 31004 KB Output is correct
12 Correct 41 ms 26444 KB Output is correct
13 Correct 35 ms 28872 KB Output is correct
14 Correct 27 ms 24756 KB Output is correct
15 Correct 28 ms 24756 KB Output is correct
16 Correct 87 ms 36268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 24488 KB Output is correct
2 Correct 46 ms 24620 KB Output is correct
3 Correct 26 ms 24496 KB Output is correct
4 Correct 30 ms 24496 KB Output is correct
5 Correct 26 ms 24496 KB Output is correct
6 Correct 24 ms 24496 KB Output is correct
7 Correct 25 ms 24500 KB Output is correct
8 Correct 26 ms 24652 KB Output is correct
9 Correct 95 ms 36264 KB Output is correct
10 Correct 30 ms 25888 KB Output is correct
11 Correct 49 ms 31004 KB Output is correct
12 Correct 41 ms 26444 KB Output is correct
13 Correct 35 ms 28872 KB Output is correct
14 Correct 27 ms 24756 KB Output is correct
15 Correct 28 ms 24756 KB Output is correct
16 Correct 87 ms 36268 KB Output is correct
17 Correct 27 ms 24748 KB Output is correct
18 Correct 27 ms 24496 KB Output is correct
19 Correct 26 ms 24500 KB Output is correct
20 Correct 27 ms 24500 KB Output is correct
21 Correct 25 ms 24488 KB Output is correct
22 Correct 26 ms 24536 KB Output is correct
23 Correct 154 ms 47404 KB Output is correct
24 Correct 25 ms 24500 KB Output is correct
25 Correct 27 ms 24696 KB Output is correct
26 Correct 28 ms 24932 KB Output is correct
27 Correct 29 ms 25012 KB Output is correct
28 Correct 71 ms 33812 KB Output is correct
29 Correct 106 ms 37660 KB Output is correct
30 Correct 122 ms 42904 KB Output is correct
31 Correct 152 ms 47636 KB Output is correct
32 Correct 30 ms 24496 KB Output is correct
33 Correct 34 ms 24684 KB Output is correct
34 Correct 26 ms 24496 KB Output is correct
35 Correct 26 ms 24500 KB Output is correct
36 Correct 27 ms 24500 KB Output is correct
37 Correct 27 ms 24592 KB Output is correct
38 Correct 26 ms 24668 KB Output is correct
39 Correct 27 ms 24492 KB Output is correct
40 Correct 26 ms 24576 KB Output is correct
41 Correct 26 ms 24576 KB Output is correct
42 Correct 26 ms 24556 KB Output is correct
43 Correct 26 ms 24756 KB Output is correct
44 Correct 34 ms 24936 KB Output is correct
45 Correct 97 ms 35368 KB Output is correct
46 Correct 134 ms 40960 KB Output is correct
47 Correct 124 ms 40984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 24488 KB Output is correct
2 Correct 46 ms 24620 KB Output is correct
3 Correct 26 ms 24496 KB Output is correct
4 Correct 30 ms 24496 KB Output is correct
5 Correct 26 ms 24496 KB Output is correct
6 Correct 24 ms 24496 KB Output is correct
7 Correct 25 ms 24500 KB Output is correct
8 Correct 26 ms 24652 KB Output is correct
9 Correct 95 ms 36264 KB Output is correct
10 Correct 30 ms 25888 KB Output is correct
11 Correct 49 ms 31004 KB Output is correct
12 Correct 41 ms 26444 KB Output is correct
13 Correct 35 ms 28872 KB Output is correct
14 Correct 27 ms 24756 KB Output is correct
15 Correct 28 ms 24756 KB Output is correct
16 Correct 87 ms 36268 KB Output is correct
17 Correct 27 ms 24748 KB Output is correct
18 Correct 27 ms 24496 KB Output is correct
19 Correct 26 ms 24500 KB Output is correct
20 Correct 27 ms 24500 KB Output is correct
21 Correct 25 ms 24488 KB Output is correct
22 Correct 26 ms 24536 KB Output is correct
23 Correct 154 ms 47404 KB Output is correct
24 Correct 25 ms 24500 KB Output is correct
25 Correct 27 ms 24696 KB Output is correct
26 Correct 28 ms 24932 KB Output is correct
27 Correct 29 ms 25012 KB Output is correct
28 Correct 71 ms 33812 KB Output is correct
29 Correct 106 ms 37660 KB Output is correct
30 Correct 122 ms 42904 KB Output is correct
31 Correct 152 ms 47636 KB Output is correct
32 Correct 30 ms 24496 KB Output is correct
33 Correct 34 ms 24684 KB Output is correct
34 Correct 26 ms 24496 KB Output is correct
35 Correct 26 ms 24500 KB Output is correct
36 Correct 27 ms 24500 KB Output is correct
37 Correct 27 ms 24592 KB Output is correct
38 Correct 26 ms 24668 KB Output is correct
39 Correct 27 ms 24492 KB Output is correct
40 Correct 26 ms 24576 KB Output is correct
41 Correct 26 ms 24576 KB Output is correct
42 Correct 26 ms 24556 KB Output is correct
43 Correct 26 ms 24756 KB Output is correct
44 Correct 34 ms 24936 KB Output is correct
45 Correct 97 ms 35368 KB Output is correct
46 Correct 134 ms 40960 KB Output is correct
47 Correct 124 ms 40984 KB Output is correct
48 Correct 27 ms 24500 KB Output is correct
49 Correct 27 ms 24500 KB Output is correct
50 Incorrect 23 ms 24500 KB Tree @(3, 3) appears more than once: for edges on positions 1 and 3
51 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 24488 KB Output is correct
2 Correct 46 ms 24620 KB Output is correct
3 Correct 26 ms 24496 KB Output is correct
4 Correct 30 ms 24496 KB Output is correct
5 Correct 26 ms 24496 KB Output is correct
6 Correct 24 ms 24496 KB Output is correct
7 Correct 25 ms 24500 KB Output is correct
8 Correct 26 ms 24652 KB Output is correct
9 Correct 95 ms 36264 KB Output is correct
10 Correct 30 ms 25888 KB Output is correct
11 Correct 49 ms 31004 KB Output is correct
12 Correct 41 ms 26444 KB Output is correct
13 Correct 35 ms 28872 KB Output is correct
14 Correct 27 ms 24756 KB Output is correct
15 Correct 28 ms 24756 KB Output is correct
16 Correct 87 ms 36268 KB Output is correct
17 Correct 25 ms 24500 KB Output is correct
18 Correct 26 ms 24740 KB Output is correct
19 Correct 24 ms 24604 KB Output is correct
20 Incorrect 190 ms 46504 KB Tree @(100003, 100001) appears more than once: for edges on positions 99997 and 99998
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 24488 KB Output is correct
2 Correct 46 ms 24620 KB Output is correct
3 Correct 26 ms 24496 KB Output is correct
4 Correct 30 ms 24496 KB Output is correct
5 Correct 26 ms 24496 KB Output is correct
6 Correct 24 ms 24496 KB Output is correct
7 Correct 25 ms 24500 KB Output is correct
8 Correct 26 ms 24652 KB Output is correct
9 Correct 95 ms 36264 KB Output is correct
10 Correct 30 ms 25888 KB Output is correct
11 Correct 49 ms 31004 KB Output is correct
12 Correct 41 ms 26444 KB Output is correct
13 Correct 35 ms 28872 KB Output is correct
14 Correct 27 ms 24756 KB Output is correct
15 Correct 28 ms 24756 KB Output is correct
16 Correct 87 ms 36268 KB Output is correct
17 Correct 147 ms 45832 KB Output is correct
18 Correct 161 ms 45720 KB Output is correct
19 Incorrect 164 ms 48804 KB Tree @(25001, 25003) appears more than once: for edges on positions 49996 and 50002
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 24488 KB Output is correct
2 Correct 46 ms 24620 KB Output is correct
3 Correct 26 ms 24496 KB Output is correct
4 Correct 30 ms 24496 KB Output is correct
5 Correct 26 ms 24496 KB Output is correct
6 Correct 24 ms 24496 KB Output is correct
7 Correct 25 ms 24500 KB Output is correct
8 Correct 26 ms 24652 KB Output is correct
9 Correct 95 ms 36264 KB Output is correct
10 Correct 30 ms 25888 KB Output is correct
11 Correct 49 ms 31004 KB Output is correct
12 Correct 41 ms 26444 KB Output is correct
13 Correct 35 ms 28872 KB Output is correct
14 Correct 27 ms 24756 KB Output is correct
15 Correct 28 ms 24756 KB Output is correct
16 Correct 87 ms 36268 KB Output is correct
17 Correct 27 ms 24748 KB Output is correct
18 Correct 27 ms 24496 KB Output is correct
19 Correct 26 ms 24500 KB Output is correct
20 Correct 27 ms 24500 KB Output is correct
21 Correct 25 ms 24488 KB Output is correct
22 Correct 26 ms 24536 KB Output is correct
23 Correct 154 ms 47404 KB Output is correct
24 Correct 25 ms 24500 KB Output is correct
25 Correct 27 ms 24696 KB Output is correct
26 Correct 28 ms 24932 KB Output is correct
27 Correct 29 ms 25012 KB Output is correct
28 Correct 71 ms 33812 KB Output is correct
29 Correct 106 ms 37660 KB Output is correct
30 Correct 122 ms 42904 KB Output is correct
31 Correct 152 ms 47636 KB Output is correct
32 Correct 30 ms 24496 KB Output is correct
33 Correct 34 ms 24684 KB Output is correct
34 Correct 26 ms 24496 KB Output is correct
35 Correct 26 ms 24500 KB Output is correct
36 Correct 27 ms 24500 KB Output is correct
37 Correct 27 ms 24592 KB Output is correct
38 Correct 26 ms 24668 KB Output is correct
39 Correct 27 ms 24492 KB Output is correct
40 Correct 26 ms 24576 KB Output is correct
41 Correct 26 ms 24576 KB Output is correct
42 Correct 26 ms 24556 KB Output is correct
43 Correct 26 ms 24756 KB Output is correct
44 Correct 34 ms 24936 KB Output is correct
45 Correct 97 ms 35368 KB Output is correct
46 Correct 134 ms 40960 KB Output is correct
47 Correct 124 ms 40984 KB Output is correct
48 Correct 27 ms 24500 KB Output is correct
49 Correct 27 ms 24500 KB Output is correct
50 Incorrect 23 ms 24500 KB Tree @(3, 3) appears more than once: for edges on positions 1 and 3
51 Halted 0 ms 0 KB -