Submission #553001

# Submission time Handle Problem Language Result Execution time Memory
553001 2022-04-24T12:23:47 Z PiejanVDC Fountain Parks (IOI21_parks) C++17
15 / 100
1485 ms 45240 KB
#include <bits/stdc++.h>
#include "parks.h"
using namespace std;

int dx[4] = {2,0,-2,0};
int dy[4] = {0,2,0,-2};

struct S {
    int x,y;
    int dir;
}s_;

void build(vector<int> u, vector<int> v, vector<int> a, vector<int> b);

const int mxN = (int)2e5 + 5;

int construct_roads(std::vector<int> x, std::vector<int> y) {
    const int n = (int)x.size();
    for(int A = 0 ; A < min(n, 10) ; A++) {
        map<pair<int,int>,int>mp;
        for(int i = 0 ; i < n ; i++)
            mp[{x[i],y[i]}] = i;
        vector<int>u(n-1),v(n-1),a(n-1),b(n-1);
        set<pair<int,int>>processed;

        stack<S>s;

        s_.x = x[A], s_.y = y[A], s_.dir = 0;
        processed.insert({x[A], y[A]});
        s.push(s_);

        int P = 0;
        while(!s.empty()) {
            auto node = s.top();
            s.pop();

            int x = node.x, y = node.y, dir = node.dir;
            bool in_order = 0;

            if(mp.count({x + dx[dir], y + dy[dir]})) in_order = 1;

            int i = dir;
            int ii = mp[{x,y}];

            int p_ = P;

            if(!in_order) {
                dir--;
                i--;
                dir += 4;
                i += 4;
                dir %= 4;
                i %= 4;
            } else {
                dir++;
                i++;
                dir += 4;
                i += 4;
                dir %= 4;
                i %= 4;
            }

            do {
                if(in_order) {
                    if(mp.count({x + dx[i], y + dy[i]}) && !processed.count({x + dx[i], y + dy[i]})) {
                        if(dx[i] == 0 && dy[i] == 2) {
                            if(!processed.count({x+1,y + dy[i]/2}))
                                a[P] = x+1, b[P] = y + dy[i]/2, u[P] = ii, v[P] = mp[{x + dx[i], y + dy[i]}], s_.x = x + dx[i], s_.y = y + dy[i], s_.dir = i, s.push(s_), processed.insert({x + dx[i], y + dy[i]}),processed.insert({a[P],b[P]}),P++;
                            else if(!processed.count({x-1,y + dy[i]/2}))
                                a[P] = x-1, b[P] = y + dy[i]/2, u[P] = ii, v[P] = mp[{x + dx[i], y + dy[i]}], s_.x = x + dx[i], s_.y = y + dy[i], s_.dir = i, s.push(s_), processed.insert({x + dx[i], y + dy[i]}),processed.insert({a[P],b[P]}),P++;
                        } else if(dx[i] == 0 && dy[i] == -2) {
                            if(!processed.count({x-1,y + dy[i]/2}))
                                a[P] = x-1, b[P] = y + dy[i]/2, u[P] = ii, v[P] = mp[{x + dx[i], y + dy[i]}], s_.x = x + dx[i], s_.y = y + dy[i], s_.dir = i, s.push(s_), processed.insert({x + dx[i], y + dy[i]}),processed.insert({a[P],b[P]}),P++;
                            else if(!processed.count({x+1,y + dy[i]/2}))
                                a[P] = x+1, b[P] = y + dy[i]/2, u[P] = ii, v[P] = mp[{x + dx[i], y + dy[i]}], s_.x = x + dx[i], s_.y = y + dy[i], s_.dir = i, s.push(s_), processed.insert({x + dx[i], y + dy[i]}),processed.insert({a[P],b[P]}),P++;
                        } else if(dy[i] == 0 && dx[i] == 2) {
                            if(!processed.count({x + dx[i]/2, y-1}))
                                a[P] = x + dx[i]/2, b[P] = y-1, u[P] = ii, v[P] = mp[{x + dx[i], y + dy[i]}], s_.x = x + dx[i], s_.y = y + dy[i], s_.dir = i, s.push(s_), processed.insert({x + dx[i], y + dy[i]}),processed.insert({a[P],b[P]}),P++;
                            else if(!processed.count({x + dx[i]/2, y+1}))
                                a[P] = x + dx[i]/2, b[P] = y+1, u[P] = ii, v[P] = mp[{x + dx[i], y + dy[i]}], s_.x = x + dx[i], s_.y = y + dy[i], s_.dir = i, s.push(s_), processed.insert({x + dx[i], y + dy[i]}),processed.insert({a[P],b[P]}),P++;
                        } else if(dy[i] == 0 && dx[i] == -2) {
                            if(!processed.count({x + dx[i]/2, y+1}))
                                a[P] = x + dx[i]/2, b[P] = y+1, u[P] = ii, v[P] = mp[{x + dx[i], y + dy[i]}], s_.x = x + dx[i], s_.y = y + dy[i], s_.dir = i, s.push(s_), processed.insert({x + dx[i], y + dy[i]}),processed.insert({a[P],b[P]}),P++;
                            else if(!processed.count({x + dx[i]/2, y-1}))
                                a[P] = x + dx[i]/2, b[P] = y-1, u[P] = ii, v[P] = mp[{x + dx[i], y + dy[i]}], s_.x = x + dx[i], s_.y = y + dy[i], s_.dir = i, s.push(s_), processed.insert({x + dx[i], y + dy[i]}),processed.insert({a[P],b[P]}),P++;
                        }
                    }
                } else {
                    if(mp.count({x + dx[i], y + dy[i]}) && !processed.count({x + dx[i], y + dy[i]})) {
                        if(dx[i] == 0 && dy[i] == 2) {
                            if(!processed.count({x-1,y + dy[i]/2}))
                                a[P] = x-1, b[P] = y + dy[i]/2, u[P] = ii, v[P] = mp[{x + dx[i], y + dy[i]}], s_.x = x + dx[i], s_.y = y + dy[i], s_.dir = i, s.push(s_), processed.insert({x + dx[i], y + dy[i]}),processed.insert({a[P],b[P]}),P++;
                            else if(!processed.count({x+1,y + dy[i]/2}))
                                a[P] = x+1, b[P] = y + dy[i]/2, u[P] = ii, v[P] = mp[{x + dx[i], y + dy[i]}], s_.x = x + dx[i], s_.y = y + dy[i], s_.dir = i, s.push(s_), processed.insert({x + dx[i], y + dy[i]}),processed.insert({a[P],b[P]}),P++;
                        } else if(dx[i] == 0 && dy[i] == -2) {
                            if(!processed.count({x+1,y + dy[i]/2}))
                                a[P] = x+1, b[P] = y + dy[i]/2, u[P] = ii, v[P] = mp[{x + dx[i], y + dy[i]}], s_.x = x + dx[i], s_.y = y + dy[i], s_.dir = i, s.push(s_), processed.insert({x + dx[i], y + dy[i]}),processed.insert({a[P],b[P]}),P++;
                            else if(!processed.count({x-1,y + dy[i]/2}))
                                a[P] = x-1, b[P] = y + dy[i]/2, u[P] = ii, v[P] = mp[{x + dx[i], y + dy[i]}], s_.x = x + dx[i], s_.y = y + dy[i], s_.dir = i, s.push(s_), processed.insert({x + dx[i], y + dy[i]}),processed.insert({a[P],b[P]}),P++;
                        } else if(dy[i] == 0 && dx[i] == 2) {
                            if(!processed.count({x + dx[i]/2, y+1}))
                                a[P] = x + dx[i]/2, b[P] = y+1, u[P] = ii, v[P] = mp[{x + dx[i], y + dy[i]}], s_.x = x + dx[i], s_.y = y + dy[i], s_.dir = i, s.push(s_), processed.insert({x + dx[i], y + dy[i]}),processed.insert({a[P],b[P]}),P++;
                            else if(!processed.count({x + dx[i]/2, y-1}))
                                a[P] = x + dx[i]/2, b[P] = y-1, u[P] = ii, v[P] = mp[{x + dx[i], y + dy[i]}], s_.x = x + dx[i], s_.y = y + dy[i], s_.dir = i, s.push(s_), processed.insert({x + dx[i], y + dy[i]}),processed.insert({a[P],b[P]}),P++;
                        } else if(dy[i] == 0 && dx[i] == -2) {
                            if(!processed.count({x + dx[i]/2, y-1}))
                                a[P] = x + dx[i]/2, b[P] = y-1, u[P] = ii, v[P] = mp[{x + dx[i], y + dy[i]}], s_.x = x + dx[i], s_.y = y + dy[i], s_.dir = i, s.push(s_), processed.insert({x + dx[i], y + dy[i]}),processed.insert({a[P],b[P]}),P++;
                            else if(!processed.count({x + dx[i]/2, y+1}))
                                a[P] = x + dx[i]/2, b[P] = y+1, u[P] = ii, v[P] = mp[{x + dx[i], y + dy[i]}], s_.x = x + dx[i], s_.y = y + dy[i], s_.dir = i, s.push(s_), processed.insert({x + dx[i], y + dy[i]}),processed.insert({a[P],b[P]}),P++;
                        }
                    }
                }
                if(in_order) i++,i%=4;
                else i--, i+=4, i%= 4;
            } while(i != dir);

        }

        if(P < n-1)
            continue;

        build(u,v,a,b);
        return 1;
    }
    return 0;
}

Compilation message

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:45:17: warning: unused variable 'p_' [-Wunused-variable]
   45 |             int p_ = P;
      |                 ^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 265 ms 22196 KB Output is correct
10 Correct 18 ms 2644 KB Output is correct
11 Correct 129 ms 12028 KB Output is correct
12 Correct 46 ms 3728 KB Output is correct
13 Correct 528 ms 7432 KB Output is correct
14 Correct 6 ms 436 KB Output is correct
15 Correct 11 ms 468 KB Output is correct
16 Correct 252 ms 22204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 265 ms 22196 KB Output is correct
10 Correct 18 ms 2644 KB Output is correct
11 Correct 129 ms 12028 KB Output is correct
12 Correct 46 ms 3728 KB Output is correct
13 Correct 528 ms 7432 KB Output is correct
14 Correct 6 ms 436 KB Output is correct
15 Correct 11 ms 468 KB Output is correct
16 Correct 252 ms 22204 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 582 ms 45240 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 20 ms 596 KB Output is correct
27 Correct 15 ms 732 KB Output is correct
28 Correct 207 ms 18252 KB Output is correct
29 Correct 294 ms 26828 KB Output is correct
30 Correct 448 ms 35472 KB Output is correct
31 Correct 541 ms 45144 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 2 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 14 ms 468 KB Output is correct
44 Correct 13 ms 636 KB Output is correct
45 Correct 258 ms 22336 KB Output is correct
46 Correct 401 ms 32120 KB Output is correct
47 Correct 444 ms 32116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 265 ms 22196 KB Output is correct
10 Correct 18 ms 2644 KB Output is correct
11 Correct 129 ms 12028 KB Output is correct
12 Correct 46 ms 3728 KB Output is correct
13 Correct 528 ms 7432 KB Output is correct
14 Correct 6 ms 436 KB Output is correct
15 Correct 11 ms 468 KB Output is correct
16 Correct 252 ms 22204 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 582 ms 45240 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 20 ms 596 KB Output is correct
27 Correct 15 ms 732 KB Output is correct
28 Correct 207 ms 18252 KB Output is correct
29 Correct 294 ms 26828 KB Output is correct
30 Correct 448 ms 35472 KB Output is correct
31 Correct 541 ms 45144 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 2 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 14 ms 468 KB Output is correct
44 Correct 13 ms 636 KB Output is correct
45 Correct 258 ms 22336 KB Output is correct
46 Correct 401 ms 32120 KB Output is correct
47 Correct 444 ms 32116 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 1 ms 256 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 603 ms 44948 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
57 Correct 3 ms 596 KB Output is correct
58 Correct 12 ms 1620 KB Output is correct
59 Correct 47 ms 1420 KB Output is correct
60 Correct 260 ms 22624 KB Output is correct
61 Correct 365 ms 30352 KB Output is correct
62 Correct 454 ms 37100 KB Output is correct
63 Correct 578 ms 44876 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 0 ms 212 KB Output is correct
67 Correct 547 ms 44088 KB Output is correct
68 Correct 553 ms 44096 KB Output is correct
69 Correct 537 ms 43836 KB Output is correct
70 Correct 11 ms 596 KB Output is correct
71 Correct 22 ms 1044 KB Output is correct
72 Incorrect 473 ms 9712 KB Solution announced impossible, but it is possible.
73 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 265 ms 22196 KB Output is correct
10 Correct 18 ms 2644 KB Output is correct
11 Correct 129 ms 12028 KB Output is correct
12 Correct 46 ms 3728 KB Output is correct
13 Correct 528 ms 7432 KB Output is correct
14 Correct 6 ms 436 KB Output is correct
15 Correct 11 ms 468 KB Output is correct
16 Correct 252 ms 22204 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 564 ms 44164 KB Output is correct
21 Correct 524 ms 44260 KB Output is correct
22 Correct 496 ms 44304 KB Output is correct
23 Correct 399 ms 37616 KB Output is correct
24 Correct 1485 ms 19232 KB Output is correct
25 Correct 1458 ms 19188 KB Output is correct
26 Correct 1395 ms 19180 KB Output is correct
27 Correct 417 ms 44116 KB Output is correct
28 Correct 411 ms 44100 KB Output is correct
29 Correct 569 ms 44096 KB Output is correct
30 Correct 567 ms 44236 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Incorrect 41 ms 1656 KB Solution announced impossible, but it is possible.
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 265 ms 22196 KB Output is correct
10 Correct 18 ms 2644 KB Output is correct
11 Correct 129 ms 12028 KB Output is correct
12 Correct 46 ms 3728 KB Output is correct
13 Correct 528 ms 7432 KB Output is correct
14 Correct 6 ms 436 KB Output is correct
15 Correct 11 ms 468 KB Output is correct
16 Correct 252 ms 22204 KB Output is correct
17 Correct 502 ms 44156 KB Output is correct
18 Correct 517 ms 44148 KB Output is correct
19 Correct 547 ms 44060 KB Output is correct
20 Correct 655 ms 44240 KB Output is correct
21 Correct 553 ms 38660 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Incorrect 282 ms 4988 KB Solution announced impossible, but it is possible.
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 265 ms 22196 KB Output is correct
10 Correct 18 ms 2644 KB Output is correct
11 Correct 129 ms 12028 KB Output is correct
12 Correct 46 ms 3728 KB Output is correct
13 Correct 528 ms 7432 KB Output is correct
14 Correct 6 ms 436 KB Output is correct
15 Correct 11 ms 468 KB Output is correct
16 Correct 252 ms 22204 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 582 ms 45240 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 20 ms 596 KB Output is correct
27 Correct 15 ms 732 KB Output is correct
28 Correct 207 ms 18252 KB Output is correct
29 Correct 294 ms 26828 KB Output is correct
30 Correct 448 ms 35472 KB Output is correct
31 Correct 541 ms 45144 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 2 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 14 ms 468 KB Output is correct
44 Correct 13 ms 636 KB Output is correct
45 Correct 258 ms 22336 KB Output is correct
46 Correct 401 ms 32120 KB Output is correct
47 Correct 444 ms 32116 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 1 ms 256 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 603 ms 44948 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
57 Correct 3 ms 596 KB Output is correct
58 Correct 12 ms 1620 KB Output is correct
59 Correct 47 ms 1420 KB Output is correct
60 Correct 260 ms 22624 KB Output is correct
61 Correct 365 ms 30352 KB Output is correct
62 Correct 454 ms 37100 KB Output is correct
63 Correct 578 ms 44876 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 0 ms 212 KB Output is correct
67 Correct 547 ms 44088 KB Output is correct
68 Correct 553 ms 44096 KB Output is correct
69 Correct 537 ms 43836 KB Output is correct
70 Correct 11 ms 596 KB Output is correct
71 Correct 22 ms 1044 KB Output is correct
72 Incorrect 473 ms 9712 KB Solution announced impossible, but it is possible.
73 Halted 0 ms 0 KB -