Submission #809069

# Submission time Handle Problem Language Result Execution time Memory
809069 2023-08-05T15:28:18 Z puppy Fountain Parks (IOI21_parks) C++17
5 / 100
89 ms 18580 KB
#include "parks.h"
#include <vector>
using namespace std;
int coord[3][100005];
bool bench[4][100005];
struct UnionFind
{
    vector<int> par;
    UnionFind(int N)
    {
        par.resize(N+1);
        for (int i = 0; i <= N; i++) par[i] = i;
    }
    int fin(int v)
    {
        return v == par[v] ? v : (par[v] = fin(par[v]));
    }
    void uni(int u, int v)
    {
        par[fin(u)] = fin(v);
    }
    bool isuni(int u, int v)
    {
        return fin(u) == fin(v);
    }
};

int construct_roads(std::vector<int> x, std::vector<int> y) {
    int N = x.size();
    fill(&coord[0][0], &coord[2][100005], -1);
    for (int i = 0; i < N; i++) {
        coord[(x[i]-2)/2][y[i]/2] = i;
    }
    UnionFind uf(N);
    vector<int> u, v, a, b;
    for (int i = 1; i < 100000; i++) {
        if (coord[0][i] != -1 && coord[0][i+1] != -1) {
            uf.uni(coord[0][i], coord[0][i+1]);
            u.push_back(coord[0][i]);
            v.push_back(coord[0][i+1]);
            a.push_back(1);
            b.push_back(2*i+1);
        }
        if (coord[2][i] != -1 && coord[2][i+1] != -1) {
            uf.uni(coord[2][i], coord[2][i+1]);
            u.push_back(coord[2][i]);
            v.push_back(coord[2][i+1]);
            a.push_back(7);
            b.push_back(2*i+1);
        }
    }
    vector<pair<int, int>> edge;
    for (int i = 1; i <= 100000; i++) {
        if (coord[0][i] != -1 && coord[1][i] != -1) {
            uf.uni(coord[0][i], coord[1][i]);
            edge.push_back(make_pair(coord[0][i], coord[1][i]));
        }
        if (coord[1][i] != -1 && coord[2][i] != -1) {
            uf.uni(coord[1][i], coord[2][i]);
            edge.push_back(make_pair(coord[1][i], coord[2][i]));
        }
    }
    bool flag = false;
    for (int i = 1; i < 100000; i++) {
        if (coord[1][i] != -1 && coord[1][i+1] != -1) {
            if (uf.isuni(coord[1][i], coord[1][i+1])) continue;
            uf.uni(coord[1][i], coord[1][i+1]);
            u.push_back(coord[1][i]);
            v.push_back(coord[1][i+1]);
            b.push_back(2*i+1);
            if (!flag) a.push_back(3);
            else a.push_back(5);
            bench[a.back()/2][b.back()/2] = true;
            flag = !flag;
        }
    }
    for (pair<int, int> p:edge) {
        u.push_back(p.first);
        v.push_back(p.second);
        int xc = x[p.first] + x[p.second] >> 1;
        int yc = y[p.first];
        a.push_back(xc);
        if (bench[xc/2][(yc+1)/2]) b.push_back(yc-1);
        else b.push_back(yc+1);
        bench[a.back()/2][b.back()/2] = true;
    }
    for (int i = 0; i < N; i++) {
        if (!uf.isuni(0, i)) return 0;
    }
    build(u, v, a, b);
    return 1;
}

Compilation message

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:80:29: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   80 |         int xc = x[p.first] + x[p.second] >> 1;
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1364 KB Output is correct
2 Correct 1 ms 1364 KB Output is correct
3 Correct 1 ms 1364 KB Output is correct
4 Correct 1 ms 1364 KB Output is correct
5 Correct 1 ms 1452 KB Output is correct
6 Correct 1 ms 1364 KB Output is correct
7 Correct 1 ms 1364 KB Output is correct
8 Correct 1 ms 1364 KB Output is correct
9 Correct 41 ms 10140 KB Output is correct
10 Correct 5 ms 2516 KB Output is correct
11 Correct 22 ms 6196 KB Output is correct
12 Correct 7 ms 2960 KB Output is correct
13 Correct 7 ms 3840 KB Output is correct
14 Correct 1 ms 1492 KB Output is correct
15 Correct 2 ms 1464 KB Output is correct
16 Correct 41 ms 9652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1364 KB Output is correct
2 Correct 1 ms 1364 KB Output is correct
3 Correct 1 ms 1364 KB Output is correct
4 Correct 1 ms 1364 KB Output is correct
5 Correct 1 ms 1452 KB Output is correct
6 Correct 1 ms 1364 KB Output is correct
7 Correct 1 ms 1364 KB Output is correct
8 Correct 1 ms 1364 KB Output is correct
9 Correct 41 ms 10140 KB Output is correct
10 Correct 5 ms 2516 KB Output is correct
11 Correct 22 ms 6196 KB Output is correct
12 Correct 7 ms 2960 KB Output is correct
13 Correct 7 ms 3840 KB Output is correct
14 Correct 1 ms 1492 KB Output is correct
15 Correct 2 ms 1464 KB Output is correct
16 Correct 41 ms 9652 KB Output is correct
17 Correct 1 ms 1364 KB Output is correct
18 Correct 1 ms 1364 KB Output is correct
19 Correct 1 ms 1364 KB Output is correct
20 Correct 1 ms 1364 KB Output is correct
21 Correct 1 ms 1452 KB Output is correct
22 Correct 1 ms 1364 KB Output is correct
23 Correct 89 ms 18580 KB Output is correct
24 Incorrect 1 ms 1364 KB Tree @(3, 183571) appears more than once: for edges on positions 4 and 5
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1364 KB Output is correct
2 Correct 1 ms 1364 KB Output is correct
3 Correct 1 ms 1364 KB Output is correct
4 Correct 1 ms 1364 KB Output is correct
5 Correct 1 ms 1452 KB Output is correct
6 Correct 1 ms 1364 KB Output is correct
7 Correct 1 ms 1364 KB Output is correct
8 Correct 1 ms 1364 KB Output is correct
9 Correct 41 ms 10140 KB Output is correct
10 Correct 5 ms 2516 KB Output is correct
11 Correct 22 ms 6196 KB Output is correct
12 Correct 7 ms 2960 KB Output is correct
13 Correct 7 ms 3840 KB Output is correct
14 Correct 1 ms 1492 KB Output is correct
15 Correct 2 ms 1464 KB Output is correct
16 Correct 41 ms 9652 KB Output is correct
17 Correct 1 ms 1364 KB Output is correct
18 Correct 1 ms 1364 KB Output is correct
19 Correct 1 ms 1364 KB Output is correct
20 Correct 1 ms 1364 KB Output is correct
21 Correct 1 ms 1452 KB Output is correct
22 Correct 1 ms 1364 KB Output is correct
23 Correct 89 ms 18580 KB Output is correct
24 Incorrect 1 ms 1364 KB Tree @(3, 183571) appears more than once: for edges on positions 4 and 5
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1364 KB Output is correct
2 Correct 1 ms 1364 KB Output is correct
3 Correct 1 ms 1364 KB Output is correct
4 Correct 1 ms 1364 KB Output is correct
5 Correct 1 ms 1452 KB Output is correct
6 Correct 1 ms 1364 KB Output is correct
7 Correct 1 ms 1364 KB Output is correct
8 Correct 1 ms 1364 KB Output is correct
9 Correct 41 ms 10140 KB Output is correct
10 Correct 5 ms 2516 KB Output is correct
11 Correct 22 ms 6196 KB Output is correct
12 Correct 7 ms 2960 KB Output is correct
13 Correct 7 ms 3840 KB Output is correct
14 Correct 1 ms 1492 KB Output is correct
15 Correct 2 ms 1464 KB Output is correct
16 Correct 41 ms 9652 KB Output is correct
17 Runtime error 2 ms 2772 KB Execution killed with signal 11
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1364 KB Output is correct
2 Correct 1 ms 1364 KB Output is correct
3 Correct 1 ms 1364 KB Output is correct
4 Correct 1 ms 1364 KB Output is correct
5 Correct 1 ms 1452 KB Output is correct
6 Correct 1 ms 1364 KB Output is correct
7 Correct 1 ms 1364 KB Output is correct
8 Correct 1 ms 1364 KB Output is correct
9 Correct 41 ms 10140 KB Output is correct
10 Correct 5 ms 2516 KB Output is correct
11 Correct 22 ms 6196 KB Output is correct
12 Correct 7 ms 2960 KB Output is correct
13 Correct 7 ms 3840 KB Output is correct
14 Correct 1 ms 1492 KB Output is correct
15 Correct 2 ms 1464 KB Output is correct
16 Correct 41 ms 9652 KB Output is correct
17 Runtime error 30 ms 11068 KB Execution killed with signal 11
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1364 KB Output is correct
2 Correct 1 ms 1364 KB Output is correct
3 Correct 1 ms 1364 KB Output is correct
4 Correct 1 ms 1364 KB Output is correct
5 Correct 1 ms 1452 KB Output is correct
6 Correct 1 ms 1364 KB Output is correct
7 Correct 1 ms 1364 KB Output is correct
8 Correct 1 ms 1364 KB Output is correct
9 Correct 41 ms 10140 KB Output is correct
10 Correct 5 ms 2516 KB Output is correct
11 Correct 22 ms 6196 KB Output is correct
12 Correct 7 ms 2960 KB Output is correct
13 Correct 7 ms 3840 KB Output is correct
14 Correct 1 ms 1492 KB Output is correct
15 Correct 2 ms 1464 KB Output is correct
16 Correct 41 ms 9652 KB Output is correct
17 Correct 1 ms 1364 KB Output is correct
18 Correct 1 ms 1364 KB Output is correct
19 Correct 1 ms 1364 KB Output is correct
20 Correct 1 ms 1364 KB Output is correct
21 Correct 1 ms 1452 KB Output is correct
22 Correct 1 ms 1364 KB Output is correct
23 Correct 89 ms 18580 KB Output is correct
24 Incorrect 1 ms 1364 KB Tree @(3, 183571) appears more than once: for edges on positions 4 and 5
25 Halted 0 ms 0 KB -