Submission #1055548

# Submission time Handle Problem Language Result Execution time Memory
1055548 2024-08-12T21:38:14 Z mariaclara Fountain Parks (IOI21_parks) C++17
30 / 100
195 ms 46264 KB
#include "parks.h"
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define mk make_pair
#define pb push_back
#define fr first
#define sc second

int construct_roads(vector<int> x, vector<int> y) {
    int n = sz(x);
    vector<pair<pii,int>> p(n);
    vector<int> u_ans, v_ans, a_ans, b_ans;
    map<pii, int> ind;

    for(int i = 0; i < n; i++)
        p[i] = {{x[i], y[i]},i}, ind[{x[i], y[i]}] = i;

    sort(all(p));

    vector<vector<pii>> v(7);
    queue<pii> inter[7];

    for(int i = 0; i < n; i++)
        v[p[i].fr.fr].pb({p[i].fr.sc, p[i].sc});

    for(int i = 0, last = -1; i < sz(v[2]); i++) {
        if(last == -1) last = v[2][i].fr;
        if(i+1 == sz(v[2]) or v[2][i+1].fr - v[2][i].fr != 2) { 
            inter[2].push({last, v[2][i].fr});
            last = -1;
            continue; 
        }
        u_ans.pb(v[2][i].sc);
        v_ans.pb(v[2][i+1].sc);
        a_ans.pb(1);
        b_ans.pb(v[2][i].fr + 1);
    }

    for(int i = 0, last = -1; i < sz(v[6]); i++) {
        if(last == -1) last = v[6][i].fr;
        if(i+1 == sz(v[6]) or v[6][i+1].fr - v[6][i].fr != 2) { 
            inter[6].push({last, v[6][i].fr});
            last = -1;
            continue; 
        } 
        u_ans.pb(v[6][i].sc);
        v_ans.pb(v[6][i+1].sc);
        a_ans.pb(7);
        b_ans.pb(v[6][i].fr + 1);
    }

    vector<pii> to_add_1, to_add_2;
    set<pii> used; // a e b

    for(int i = 0, last = -1; i < sz(v[4]); i++) {
        int pos = v[4][i].fr;

        if(last == -1) last = pos;

        if(sz(inter[2]) and inter[2].front().sc < pos) inter[2].pop();
        if(sz(inter[2]) and inter[2].front().fr <= pos and pos <= inter[2].front().sc) {
            if(last > pos-2 or inter[2].front().fr > pos-2) {
                u_ans.pb(v[4][i].sc);
                v_ans.pb(ind[{2,pos}]);
                a_ans.pb({3});
                b_ans.pb({pos-1});
                used.insert({3, pos-1});
            }
        }

        if(sz(inter[6]) and inter[6].front().sc < pos) inter[6].pop();
        if(sz(inter[6]) and inter[6].front().fr <= pos and pos <= inter[6].front().sc) {
            if(last > pos-2 or inter[6].front().fr > pos-2) to_add_2.pb({v[4][i].sc, ind[{6,pos}]});
        }

        if(i+1 == sz(v[4]) or v[4][i+1].fr - v[4][i].fr != 2) last = -1;
        else if(i+1 < sz(v[4])) to_add_1.pb({v[4][i].sc, v[4][i+1].sc});
    }

    for(auto [A,B] : to_add_1) {
        if(used.count({3,y[A]+1})) {
            u_ans.pb(A);
            v_ans.pb(B);
            a_ans.pb(5);
            b_ans.pb(y[A]+1);
            used.insert({5,y[A]+1});
        }
        else {
            u_ans.pb(A);
            v_ans.pb(B);
            a_ans.pb(3);
            b_ans.pb(y[A]+1);
        }
    }

    for(auto [A,B] : to_add_2) {
        if(used.count({5,y[A]-1})) {
            u_ans.pb(A);
            v_ans.pb(B);
            a_ans.pb(5);
            b_ans.pb(y[A]+1);
        }
        else {
            u_ans.pb(A);
            v_ans.pb(B);
            a_ans.pb(5);
            b_ans.pb(y[A]-1);
        }
    }

    vector<int> edges[n];

    for(int i = 0; i < sz(u_ans); i++) 
        edges[u_ans[i]].pb(v_ans[i]), edges[v_ans[i]].pb(u_ans[i]);
    queue<int> fila;
    vector<bool> vis(n);
    fila.push(0);
    vis[0] = 1;

    while(!fila.empty()) {
        int at = fila.front();
        fila.pop();

        for(int viz : edges[at])
            if(!vis[viz]) fila.push(viz), vis[viz] = 1;
    }

    for(int i = 0; i < n; i++) if(!vis[i]) return 0;

    build(u_ans, v_ans, a_ans, b_ans);
    return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 436 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 72 ms 21228 KB Output is correct
10 Correct 5 ms 2568 KB Output is correct
11 Correct 34 ms 11604 KB Output is correct
12 Correct 7 ms 3496 KB Output is correct
13 Correct 15 ms 8156 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 68 ms 21276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 436 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 72 ms 21228 KB Output is correct
10 Correct 5 ms 2568 KB Output is correct
11 Correct 34 ms 11604 KB Output is correct
12 Correct 7 ms 3496 KB Output is correct
13 Correct 15 ms 8156 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 68 ms 21276 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 167 ms 43000 KB Output is correct
24 Correct 0 ms 432 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 860 KB Output is correct
27 Correct 2 ms 1116 KB Output is correct
28 Correct 67 ms 17352 KB Output is correct
29 Correct 99 ms 25812 KB Output is correct
30 Correct 143 ms 34568 KB Output is correct
31 Correct 164 ms 42964 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 ms 436 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 436 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 432 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
44 Correct 2 ms 968 KB Output is correct
45 Correct 85 ms 23676 KB Output is correct
46 Correct 140 ms 34636 KB Output is correct
47 Correct 139 ms 34628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 436 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 72 ms 21228 KB Output is correct
10 Correct 5 ms 2568 KB Output is correct
11 Correct 34 ms 11604 KB Output is correct
12 Correct 7 ms 3496 KB Output is correct
13 Correct 15 ms 8156 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 68 ms 21276 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 167 ms 43000 KB Output is correct
24 Correct 0 ms 432 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 860 KB Output is correct
27 Correct 2 ms 1116 KB Output is correct
28 Correct 67 ms 17352 KB Output is correct
29 Correct 99 ms 25812 KB Output is correct
30 Correct 143 ms 34568 KB Output is correct
31 Correct 164 ms 42964 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 ms 436 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 436 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 432 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
44 Correct 2 ms 968 KB Output is correct
45 Correct 85 ms 23676 KB Output is correct
46 Correct 140 ms 34636 KB Output is correct
47 Correct 139 ms 34628 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 177 ms 42768 KB Output is correct
56 Correct 1 ms 344 KB Output is correct
57 Correct 1 ms 700 KB Output is correct
58 Correct 5 ms 1628 KB Output is correct
59 Correct 4 ms 2140 KB Output is correct
60 Correct 71 ms 21576 KB Output is correct
61 Correct 101 ms 28616 KB Output is correct
62 Correct 131 ms 35116 KB Output is correct
63 Correct 167 ms 42700 KB Output is correct
64 Correct 0 ms 344 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 159 ms 42196 KB Output is correct
68 Correct 161 ms 42116 KB Output is correct
69 Correct 163 ms 41924 KB Output is correct
70 Correct 2 ms 1112 KB Output is correct
71 Correct 4 ms 1884 KB Output is correct
72 Correct 81 ms 22600 KB Output is correct
73 Correct 135 ms 33856 KB Output is correct
74 Correct 190 ms 45004 KB Output is correct
75 Correct 195 ms 46012 KB Output is correct
76 Correct 183 ms 42192 KB Output is correct
77 Correct 2 ms 1368 KB Output is correct
78 Correct 4 ms 2136 KB Output is correct
79 Correct 83 ms 23100 KB Output is correct
80 Correct 131 ms 34624 KB Output is correct
81 Correct 193 ms 46264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 436 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 72 ms 21228 KB Output is correct
10 Correct 5 ms 2568 KB Output is correct
11 Correct 34 ms 11604 KB Output is correct
12 Correct 7 ms 3496 KB Output is correct
13 Correct 15 ms 8156 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 68 ms 21276 KB Output is correct
17 Runtime error 1 ms 600 KB Execution killed with signal 11
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 436 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 72 ms 21228 KB Output is correct
10 Correct 5 ms 2568 KB Output is correct
11 Correct 34 ms 11604 KB Output is correct
12 Correct 7 ms 3496 KB Output is correct
13 Correct 15 ms 8156 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 68 ms 21276 KB Output is correct
17 Runtime error 101 ms 40008 KB Execution killed with signal 11
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 436 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 72 ms 21228 KB Output is correct
10 Correct 5 ms 2568 KB Output is correct
11 Correct 34 ms 11604 KB Output is correct
12 Correct 7 ms 3496 KB Output is correct
13 Correct 15 ms 8156 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 68 ms 21276 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 167 ms 43000 KB Output is correct
24 Correct 0 ms 432 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 860 KB Output is correct
27 Correct 2 ms 1116 KB Output is correct
28 Correct 67 ms 17352 KB Output is correct
29 Correct 99 ms 25812 KB Output is correct
30 Correct 143 ms 34568 KB Output is correct
31 Correct 164 ms 42964 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 ms 436 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 436 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 432 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
44 Correct 2 ms 968 KB Output is correct
45 Correct 85 ms 23676 KB Output is correct
46 Correct 140 ms 34636 KB Output is correct
47 Correct 139 ms 34628 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 177 ms 42768 KB Output is correct
56 Correct 1 ms 344 KB Output is correct
57 Correct 1 ms 700 KB Output is correct
58 Correct 5 ms 1628 KB Output is correct
59 Correct 4 ms 2140 KB Output is correct
60 Correct 71 ms 21576 KB Output is correct
61 Correct 101 ms 28616 KB Output is correct
62 Correct 131 ms 35116 KB Output is correct
63 Correct 167 ms 42700 KB Output is correct
64 Correct 0 ms 344 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 159 ms 42196 KB Output is correct
68 Correct 161 ms 42116 KB Output is correct
69 Correct 163 ms 41924 KB Output is correct
70 Correct 2 ms 1112 KB Output is correct
71 Correct 4 ms 1884 KB Output is correct
72 Correct 81 ms 22600 KB Output is correct
73 Correct 135 ms 33856 KB Output is correct
74 Correct 190 ms 45004 KB Output is correct
75 Correct 195 ms 46012 KB Output is correct
76 Correct 183 ms 42192 KB Output is correct
77 Correct 2 ms 1368 KB Output is correct
78 Correct 4 ms 2136 KB Output is correct
79 Correct 83 ms 23100 KB Output is correct
80 Correct 131 ms 34624 KB Output is correct
81 Correct 193 ms 46264 KB Output is correct
82 Runtime error 1 ms 600 KB Execution killed with signal 11
83 Halted 0 ms 0 KB -