Submission #617820

# Submission time Handle Problem Language Result Execution time Memory
617820 2022-08-01T14:54:21 Z happypotato Fountain Parks (IOI21_parks) C++17
30 / 100
582 ms 49312 KB
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
const int mxN = 2e5 + 1;
const int dx[mxN] = {0, 1, 0, -1}, dy[mxN] = {1, 0, -1, 0};
bool vis[mxN];
pair<pii, int> pts[mxN];
pii opts[mxN];
map<pii, int> allpts;
int n;
vector<pii> edges;
vector<pii> imp;
bool CheckConnected() {
    queue<pii> q;
    set<pii> track;
    q.push(pts[0].ff);
    track.insert(pts[0].ff);
    while (!q.empty()) {
        pii cur = q.front();
        q.pop();
        for (int k = 0; k < 4; k++) {
            int nx = cur.ff + dx[k] * 2;
            int ny = cur.ss + dy[k] * 2;
            if (allpts.find({nx, ny}) != allpts.end() && track.find({nx, ny}) == track.end()) {
                q.push({nx, ny});
                track.insert({nx, ny});
                edges.pb({allpts[cur], allpts[{nx, ny}]});
            }
        }
    }
    return (int(track.size()) == n);
}
void st123() {
    int arr[3][mxN + 10];
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < mxN + 10; j++) {
            arr[i][j] = -1;
        }
    }
    for (int i = 0; i < n; i++) {
        arr[(pts[i].ff.ff >> 1) - 1][pts[i].ff.ss] = pts[i].ss;
    }
    bool con01 = false, con12 = false;
    bool notfix = false;
    vector<int> u, v, a, b;
    for (int i = 0; i < mxN + 6; i += 2) {
        // if (i <= 10) cout << arr[0][i] << ' ' << arr[1][i] << ' ' << arr[2][i] << endl;
        if (arr[0][i] >= 0 && arr[0][i + 2] >= 0) {
            u.pb(arr[0][i]); v.pb(arr[0][i + 2]);
            a.pb(1); b.pb(i + 1);
        }
        if (arr[2][i] >= 0 && arr[2][i + 2] >= 0) {
            u.pb(arr[2][i]); v.pb(arr[2][i + 2]);
            a.pb(7); b.pb(i + 1);
        }
        bool special = false;
        if (notfix) {
            u.pb(arr[0][i]); v.pb(arr[1][i]);
            a.pb(3); b.pb(i + 1);
            special = true;
            notfix = false;
        }
        bool usemid = false;
        if (!(arr[1][i + 2] >= 0 && arr[2][i + 2] >= 0 && !con12)) special = true;
        if (arr[1][i] >= 0 && arr[1][i + 2] >= 0) {
            u.pb(arr[1][i]); v.pb(arr[1][i + 2]);
            a.pb((special ? 5 : 3)); b.pb(i + 1);
            usemid = !special;
        }
        if (arr[0][i + 2] >= 0 && arr[1][i + 2] >= 0 && !con01) {
            if (!usemid) {
                u.pb(arr[0][i + 2]); v.pb(arr[1][i + 2]);
                a.pb(3); b.pb(i + 1);
            } else notfix = true;
            con01 = true;
        } else con01 = false;
        if (arr[1][i + 2] >= 0 && arr[2][i + 2] >= 0 && !con12) {
            u.pb(arr[1][i + 2]); v.pb(arr[2][i + 2]);
            a.pb(5); b.pb(i + 1);
            con12 = true;
        } else con12 = false;
    }
    build(u, v, a, b);
    return;
}
bool operator<(pii a, pii b) {
    if (a.ff != b.ff) return a.ff < b.ff;
    return a.ss < b.ss;
}
void st45() {
    set<pair<pii, pii> > edgeset;
    for (pii &cur : edges) {
        pair<pii, pii> edge = {opts[cur.ff], opts[cur.ss]};
        if (edge.ff > edge.ss) swap(edge.ff, edge.ss);
        edgeset.insert(edge);
    }
    vector<int> ordering[4];
    for (int i = 0; i < edges.size(); i++) {
        pii fir = opts[edges[i].ff], sec = opts[edges[i].ss];
        pii important;
        bool left, right, middle;
        if (fir.ff == sec.ff) {
            // -2
            left = (edgeset.find({{fir.ff - 2, fir.ss}, fir}) != edgeset.end());
            right = (edgeset.find({{sec.ff - 2, sec.ss}, sec}) != edgeset.end());
            middle = (edgeset.find({{fir.ff - 2, fir.ss}, {sec.ff - 2, sec.ss}}) != edgeset.end());
            if (left && right) important.ff = 3;
            else if (middle) important.ff = 2;
            else if (left || right) important.ff = 1;
            else important.ff = 0;
            // +2
            left = (edgeset.find({fir, {fir.ff + 2, fir.ss}}) != edgeset.end());
            right = (edgeset.find({sec, {sec.ff + 2, sec.ss}}) != edgeset.end());
            middle = (edgeset.find({{fir.ff + 2, fir.ss}, {sec.ff + 2, sec.ss}}) != edgeset.end());
            if (left && right) important.ss = 3;
            else if (middle) important.ss = 2;
            else if (left || right) important.ss = 1;
            else important.ss = 0;
        } else if (fir.ss == sec.ss) {
            // -2
            left = (edgeset.find({{fir.ff, fir.ss - 2}, fir}) != edgeset.end());
            right = (edgeset.find({{sec.ff, sec.ss - 2}, sec}) != edgeset.end());
            left = (edgeset.find({{fir.ff, fir.ss - 2}, {sec.ff, sec.ss - 2}}) != edgeset.end());
            if (left && right) important.ff = 3;
            else if (middle) important.ff = 2;
            else if (left || right) important.ff = 1;
            else important.ff = 0;
            // +2
            left = (edgeset.find({fir, {fir.ff, fir.ss + 2}}) != edgeset.end());
            right = (edgeset.find({sec, {sec.ff, sec.ss + 2}}) != edgeset.end());
            left = (edgeset.find({{fir.ff, fir.ss + 2}, {sec.ff, sec.ss + 2}}) != edgeset.end());
            if (left && right) important.ss = 3;
            else if (middle) important.ss = 2;
            else if (left || right) important.ss = 1;
            else important.ss = 0;
        }
        imp.pb(important);
        ordering[max(important.ff, important.ss)].pb(i);
    }
    int m = edges.size();
    vector<pii> coor(m);
    for (int urgency = 3; urgency >= 0; urgency--) {
        for (int &cur : ordering[urgency]) {
            pii fir = opts[edges[cur].ff], sec = opts[edges[cur].ss];
            if (imp[cur].ff >= imp[cur].ss) {
                // add
                coor[cur] = {fir.ff + 1, fir.ss + 1};
            } else {
                // minus
                coor[cur] = {sec.ff - 1, sec.ss - 1};
            }
        }
    }
    vector<int> u(m), v(m), a(m), b(m);
    for (int i = 0; i < m; i++) {
        u[i] = edges[i].ff;
        v[i] = edges[i].ss;
        a[i] = coor[i].ff;
        b[i] = coor[i].ss;
    }
    build(u, v, a, b);
    return;
}
int construct_roads(vector<int> ox, vector<int> oy) {
    n = ox.size();
    int maxx = 0;
    for (int i = 0; i < n; i++) {
        pts[i] = {{ox[i], oy[i]}, i};
        opts[i] = pts[i].ff;
        allpts[pts[i].ff] = i;
        maxx = max(maxx, pts[i].ff.ff);
    }
    // for (int i = 0; i < n; i++) {
    //     cout << pts[i].ff.ff << ' ' << pts[i].ff.ss << ' ' << pts[i].ss << endl;
    // }
    if (!CheckConnected()) return 0;
    if (maxx <= 6) st123();
    else st45();
    return 1;
}

Compilation message

parks.cpp: In function 'void st45()':
parks.cpp:103:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  103 |     for (int i = 0; i < edges.size(); i++) {
      |                     ~~^~~~~~~~~~~~~~
parks.cpp:138:18: warning: 'middle' may be used uninitialized in this function [-Wmaybe-uninitialized]
  138 |             else if (middle) important.ss = 2;
      |                  ^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 155 ms 20324 KB Output is correct
10 Correct 14 ms 4564 KB Output is correct
11 Correct 85 ms 11880 KB Output is correct
12 Correct 23 ms 5276 KB Output is correct
13 Correct 41 ms 6300 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 480 KB Output is correct
16 Correct 169 ms 20648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 155 ms 20324 KB Output is correct
10 Correct 14 ms 4564 KB Output is correct
11 Correct 85 ms 11880 KB Output is correct
12 Correct 23 ms 5276 KB Output is correct
13 Correct 41 ms 6300 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 480 KB Output is correct
16 Correct 169 ms 20648 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 2644 KB Output is correct
23 Correct 447 ms 40876 KB Output is correct
24 Correct 2 ms 2644 KB Output is correct
25 Correct 4 ms 2900 KB Output is correct
26 Correct 3 ms 596 KB Output is correct
27 Correct 2 ms 724 KB Output is correct
28 Correct 143 ms 18088 KB Output is correct
29 Correct 246 ms 25476 KB Output is correct
30 Correct 344 ms 34872 KB Output is correct
31 Correct 420 ms 41880 KB Output is correct
32 Correct 2 ms 2644 KB Output is correct
33 Correct 2 ms 2644 KB Output is correct
34 Correct 1 ms 2644 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 2 ms 2644 KB Output is correct
38 Correct 2 ms 2644 KB Output is correct
39 Correct 2 ms 2644 KB Output is correct
40 Correct 2 ms 2644 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 2644 KB Output is correct
43 Correct 2 ms 468 KB Output is correct
44 Correct 2 ms 596 KB Output is correct
45 Correct 195 ms 20656 KB Output is correct
46 Correct 265 ms 30104 KB Output is correct
47 Correct 259 ms 30140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 155 ms 20324 KB Output is correct
10 Correct 14 ms 4564 KB Output is correct
11 Correct 85 ms 11880 KB Output is correct
12 Correct 23 ms 5276 KB Output is correct
13 Correct 41 ms 6300 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 480 KB Output is correct
16 Correct 169 ms 20648 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 2644 KB Output is correct
23 Correct 447 ms 40876 KB Output is correct
24 Correct 2 ms 2644 KB Output is correct
25 Correct 4 ms 2900 KB Output is correct
26 Correct 3 ms 596 KB Output is correct
27 Correct 2 ms 724 KB Output is correct
28 Correct 143 ms 18088 KB Output is correct
29 Correct 246 ms 25476 KB Output is correct
30 Correct 344 ms 34872 KB Output is correct
31 Correct 420 ms 41880 KB Output is correct
32 Correct 2 ms 2644 KB Output is correct
33 Correct 2 ms 2644 KB Output is correct
34 Correct 1 ms 2644 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 2 ms 2644 KB Output is correct
38 Correct 2 ms 2644 KB Output is correct
39 Correct 2 ms 2644 KB Output is correct
40 Correct 2 ms 2644 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 2644 KB Output is correct
43 Correct 2 ms 468 KB Output is correct
44 Correct 2 ms 596 KB Output is correct
45 Correct 195 ms 20656 KB Output is correct
46 Correct 265 ms 30104 KB Output is correct
47 Correct 259 ms 30140 KB Output is correct
48 Correct 2 ms 2644 KB Output is correct
49 Correct 2 ms 2644 KB Output is correct
50 Correct 1 ms 2644 KB Output is correct
51 Correct 2 ms 2644 KB Output is correct
52 Correct 2 ms 2644 KB Output is correct
53 Correct 2 ms 2644 KB Output is correct
54 Correct 2 ms 2644 KB Output is correct
55 Correct 468 ms 41576 KB Output is correct
56 Correct 1 ms 2644 KB Output is correct
57 Correct 4 ms 3028 KB Output is correct
58 Correct 13 ms 3804 KB Output is correct
59 Correct 6 ms 1364 KB Output is correct
60 Correct 206 ms 21784 KB Output is correct
61 Correct 283 ms 30080 KB Output is correct
62 Correct 418 ms 36500 KB Output is correct
63 Correct 487 ms 41456 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 2 ms 2644 KB Output is correct
66 Correct 1 ms 212 KB Output is correct
67 Correct 404 ms 38180 KB Output is correct
68 Correct 375 ms 38296 KB Output is correct
69 Correct 392 ms 38840 KB Output is correct
70 Correct 3 ms 772 KB Output is correct
71 Correct 6 ms 1108 KB Output is correct
72 Correct 200 ms 20212 KB Output is correct
73 Correct 284 ms 30468 KB Output is correct
74 Correct 466 ms 38260 KB Output is correct
75 Correct 464 ms 40468 KB Output is correct
76 Correct 393 ms 38956 KB Output is correct
77 Correct 4 ms 852 KB Output is correct
78 Correct 6 ms 1336 KB Output is correct
79 Correct 179 ms 21440 KB Output is correct
80 Correct 317 ms 31796 KB Output is correct
81 Correct 426 ms 39740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 155 ms 20324 KB Output is correct
10 Correct 14 ms 4564 KB Output is correct
11 Correct 85 ms 11880 KB Output is correct
12 Correct 23 ms 5276 KB Output is correct
13 Correct 41 ms 6300 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 480 KB Output is correct
16 Correct 169 ms 20648 KB Output is correct
17 Incorrect 1 ms 212 KB Tree (a[1], b[1]) = (200001, 3) is not adjacent to edge between u[1]=0 @(200000, 2) and v[1]=2 @(199998, 2)
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 155 ms 20324 KB Output is correct
10 Correct 14 ms 4564 KB Output is correct
11 Correct 85 ms 11880 KB Output is correct
12 Correct 23 ms 5276 KB Output is correct
13 Correct 41 ms 6300 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 480 KB Output is correct
16 Correct 169 ms 20648 KB Output is correct
17 Incorrect 582 ms 49312 KB Tree (a[1], b[1]) = (82423, 100003) is not adjacent to edge between u[1]=0 @(82422, 100002) and v[1]=148989 @(82420, 100002)
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 155 ms 20324 KB Output is correct
10 Correct 14 ms 4564 KB Output is correct
11 Correct 85 ms 11880 KB Output is correct
12 Correct 23 ms 5276 KB Output is correct
13 Correct 41 ms 6300 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 480 KB Output is correct
16 Correct 169 ms 20648 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 2644 KB Output is correct
23 Correct 447 ms 40876 KB Output is correct
24 Correct 2 ms 2644 KB Output is correct
25 Correct 4 ms 2900 KB Output is correct
26 Correct 3 ms 596 KB Output is correct
27 Correct 2 ms 724 KB Output is correct
28 Correct 143 ms 18088 KB Output is correct
29 Correct 246 ms 25476 KB Output is correct
30 Correct 344 ms 34872 KB Output is correct
31 Correct 420 ms 41880 KB Output is correct
32 Correct 2 ms 2644 KB Output is correct
33 Correct 2 ms 2644 KB Output is correct
34 Correct 1 ms 2644 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 2 ms 2644 KB Output is correct
38 Correct 2 ms 2644 KB Output is correct
39 Correct 2 ms 2644 KB Output is correct
40 Correct 2 ms 2644 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 2644 KB Output is correct
43 Correct 2 ms 468 KB Output is correct
44 Correct 2 ms 596 KB Output is correct
45 Correct 195 ms 20656 KB Output is correct
46 Correct 265 ms 30104 KB Output is correct
47 Correct 259 ms 30140 KB Output is correct
48 Correct 2 ms 2644 KB Output is correct
49 Correct 2 ms 2644 KB Output is correct
50 Correct 1 ms 2644 KB Output is correct
51 Correct 2 ms 2644 KB Output is correct
52 Correct 2 ms 2644 KB Output is correct
53 Correct 2 ms 2644 KB Output is correct
54 Correct 2 ms 2644 KB Output is correct
55 Correct 468 ms 41576 KB Output is correct
56 Correct 1 ms 2644 KB Output is correct
57 Correct 4 ms 3028 KB Output is correct
58 Correct 13 ms 3804 KB Output is correct
59 Correct 6 ms 1364 KB Output is correct
60 Correct 206 ms 21784 KB Output is correct
61 Correct 283 ms 30080 KB Output is correct
62 Correct 418 ms 36500 KB Output is correct
63 Correct 487 ms 41456 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 2 ms 2644 KB Output is correct
66 Correct 1 ms 212 KB Output is correct
67 Correct 404 ms 38180 KB Output is correct
68 Correct 375 ms 38296 KB Output is correct
69 Correct 392 ms 38840 KB Output is correct
70 Correct 3 ms 772 KB Output is correct
71 Correct 6 ms 1108 KB Output is correct
72 Correct 200 ms 20212 KB Output is correct
73 Correct 284 ms 30468 KB Output is correct
74 Correct 466 ms 38260 KB Output is correct
75 Correct 464 ms 40468 KB Output is correct
76 Correct 393 ms 38956 KB Output is correct
77 Correct 4 ms 852 KB Output is correct
78 Correct 6 ms 1336 KB Output is correct
79 Correct 179 ms 21440 KB Output is correct
80 Correct 317 ms 31796 KB Output is correct
81 Correct 426 ms 39740 KB Output is correct
82 Incorrect 1 ms 212 KB Tree (a[1], b[1]) = (200001, 3) is not adjacent to edge between u[1]=0 @(200000, 2) and v[1]=2 @(199998, 2)
83 Halted 0 ms 0 KB -