Submission #1069487

# Submission time Handle Problem Language Result Execution time Memory
1069487 2024-08-22T02:34:03 Z GusterGoose27 Fountain Parks (IOI21_parks) C++17
45 / 100
823 ms 103612 KB
#include "parks.h"

#include <bits/stdc++.h>

using namespace std;

#define sz(s) ((int)s.size())

typedef array<int, 2> ar2;
// set<ar2> pts;
map<ar2, ar2> edges;
map<ar2, int> pts;
// set<ar2> edges;
set<ar2> vis;
int n;
vector<int> u, v, a, b;
set<ar2> matched;

vector<ar2> adj2({{2, 0}, {0, 2}, {-2, 0}, {0, -2}});
vector<ar2> adj({{1, 0}, {0, 1}, {-1, 0}, {0, -1}});

ar2 operator+(ar2 a, ar2 b) {
    return {a[0]+b[0], a[1]+b[1]};
}

ar2 operator-(ar2 a, ar2 b) {
    return {a[0]-b[0], a[1]-b[1]};
}

void dfs(ar2 cur) {
    vis.insert(cur);
    for (int i = 0; i < 4; i++) {
        ar2 nxt = cur+adj2[i];
        if (pts.find(nxt) == pts.end() || vis.find(nxt) != vis.end()) {
            continue;
        }
        ar2 epos = cur+adj[i];
        // edges.insert(epos);
        edges[epos] = {pts[cur], pts[nxt]};
        dfs(nxt);
    }
}

bool is_real(ar2 &square) {
    int s = 0;
    for (ar2 v1: adj) s += (edges.find(square+v1) != edges.end());
    return s <= 2;
}

void match(ar2 e);

bool match(ar2 edge, ar2 sq) {
    bool comp = !is_real(sq);
    bool virt = ((edge[1]&1)&&comp);
    if (virt) sq = {-sq[0], -sq[1]};
    if (matched.find(sq) != matched.end()) return 0;
    if (!virt) {
        u.push_back(edges[edge][0]);
        v.push_back(edges[edge][1]);
        a.push_back(sq[0]);
        b.push_back(sq[1]);
    }
    matched.insert(sq);
    matched.insert(edge);
    if (comp) match(sq+sq-edge); // must exist
    else {
        for (ar2 v1: adj) {
            if (edges.find(sq+v1) != edges.end() && matched.find(sq+v1) == matched.end()) match(sq+v1);
        }
    }
    return 1;
}

void match(ar2 edge) {
    if (matched.find(edge) != matched.end()) return;
    if (edge[0]&1) { // horizontal edge
        if (!match(edge, edge+ar2({0,1}))) assert(match(edge, edge+ar2({0, -1})));
    }
    else if (!match(edge, edge+ar2({1, 0}))) assert(match(edge, edge+ar2({-1, 0})));
}

int construct_roads(vector<int> x, vector<int> y) {
    n = sz(x);
    for (int i = 0; i < n; i++) {
        // pts.insert({x[i], y[i]});
        pts[{x[i], y[i]}] = i;
    }
    dfs({x[0], y[0]});
    if (sz(vis) != n) return 0;
    for (auto v: edges) match(v.first);
    build(u, v, a, b);
    return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 436 KB Output is correct
2 Correct 0 ms 348 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 311 ms 47032 KB Output is correct
10 Correct 25 ms 5208 KB Output is correct
11 Correct 161 ms 26108 KB Output is correct
12 Correct 38 ms 7764 KB Output is correct
13 Correct 42 ms 11600 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 297 ms 41360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 436 KB Output is correct
2 Correct 0 ms 348 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 311 ms 47032 KB Output is correct
10 Correct 25 ms 5208 KB Output is correct
11 Correct 161 ms 26108 KB Output is correct
12 Correct 38 ms 7764 KB Output is correct
13 Correct 42 ms 11600 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 297 ms 41360 KB Output is correct
17 Incorrect 0 ms 348 KB Pair u[0]=0 @(4, 4) and v[0]=0 @(4, 4) does not form a valid edge (distance != 2)
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 436 KB Output is correct
2 Correct 0 ms 348 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 311 ms 47032 KB Output is correct
10 Correct 25 ms 5208 KB Output is correct
11 Correct 161 ms 26108 KB Output is correct
12 Correct 38 ms 7764 KB Output is correct
13 Correct 42 ms 11600 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 297 ms 41360 KB Output is correct
17 Incorrect 0 ms 348 KB Pair u[0]=0 @(4, 4) and v[0]=0 @(4, 4) does not form a valid edge (distance != 2)
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 436 KB Output is correct
2 Correct 0 ms 348 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 311 ms 47032 KB Output is correct
10 Correct 25 ms 5208 KB Output is correct
11 Correct 161 ms 26108 KB Output is correct
12 Correct 38 ms 7764 KB Output is correct
13 Correct 42 ms 11600 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 297 ms 41360 KB Output is correct
17 Correct 0 ms 428 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 823 ms 103588 KB Output is correct
21 Correct 687 ms 90864 KB Output is correct
22 Correct 807 ms 87636 KB Output is correct
23 Correct 567 ms 73324 KB Output is correct
24 Correct 88 ms 17732 KB Output is correct
25 Correct 88 ms 17672 KB Output is correct
26 Correct 86 ms 17748 KB Output is correct
27 Correct 564 ms 67996 KB Output is correct
28 Correct 505 ms 67748 KB Output is correct
29 Correct 712 ms 67896 KB Output is correct
30 Correct 704 ms 67948 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 38 ms 6292 KB Output is correct
33 Correct 42 ms 9296 KB Output is correct
34 Correct 758 ms 103612 KB Output is correct
35 Correct 8 ms 1884 KB Output is correct
36 Correct 29 ms 5948 KB Output is correct
37 Correct 51 ms 10580 KB Output is correct
38 Correct 263 ms 27980 KB Output is correct
39 Correct 360 ms 38080 KB Output is correct
40 Correct 491 ms 48580 KB Output is correct
41 Correct 587 ms 58800 KB Output is correct
42 Correct 703 ms 69316 KB Output is correct
43 Correct 0 ms 344 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 1 ms 344 KB Output is correct
51 Correct 0 ms 344 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 2 ms 704 KB Output is correct
55 Correct 2 ms 600 KB Output is correct
56 Correct 315 ms 42888 KB Output is correct
57 Correct 478 ms 62628 KB Output is correct
58 Correct 486 ms 61860 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 1 ms 348 KB Output is correct
62 Correct 645 ms 87812 KB Output is correct
63 Correct 661 ms 88316 KB Output is correct
64 Correct 657 ms 90880 KB Output is correct
65 Correct 3 ms 1112 KB Output is correct
66 Correct 4 ms 1372 KB Output is correct
67 Correct 327 ms 38688 KB Output is correct
68 Correct 523 ms 61488 KB Output is correct
69 Correct 729 ms 77504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 436 KB Output is correct
2 Correct 0 ms 348 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 311 ms 47032 KB Output is correct
10 Correct 25 ms 5208 KB Output is correct
11 Correct 161 ms 26108 KB Output is correct
12 Correct 38 ms 7764 KB Output is correct
13 Correct 42 ms 11600 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 297 ms 41360 KB Output is correct
17 Correct 632 ms 96308 KB Output is correct
18 Correct 595 ms 85316 KB Output is correct
19 Correct 721 ms 96920 KB Output is correct
20 Correct 772 ms 84648 KB Output is correct
21 Correct 552 ms 73160 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 85 ms 12628 KB Output is correct
24 Correct 18 ms 3932 KB Output is correct
25 Correct 39 ms 8888 KB Output is correct
26 Correct 83 ms 13400 KB Output is correct
27 Correct 348 ms 43140 KB Output is correct
28 Correct 448 ms 54060 KB Output is correct
29 Correct 564 ms 64736 KB Output is correct
30 Correct 642 ms 74912 KB Output is correct
31 Correct 747 ms 85832 KB Output is correct
32 Correct 775 ms 89652 KB Output is correct
33 Correct 644 ms 96172 KB Output is correct
34 Correct 4 ms 1112 KB Output is correct
35 Correct 6 ms 1884 KB Output is correct
36 Correct 338 ms 41260 KB Output is correct
37 Correct 547 ms 62976 KB Output is correct
38 Correct 713 ms 80292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 436 KB Output is correct
2 Correct 0 ms 348 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 311 ms 47032 KB Output is correct
10 Correct 25 ms 5208 KB Output is correct
11 Correct 161 ms 26108 KB Output is correct
12 Correct 38 ms 7764 KB Output is correct
13 Correct 42 ms 11600 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 297 ms 41360 KB Output is correct
17 Incorrect 0 ms 348 KB Pair u[0]=0 @(4, 4) and v[0]=0 @(4, 4) does not form a valid edge (distance != 2)
18 Halted 0 ms 0 KB -