Submission #553000

# Submission time Handle Problem Language Result Execution time Memory
553000 2022-04-24T12:23:23 Z PiejanVDC Fountain Parks (IOI21_parks) C++17
15 / 100
3384 ms 45268 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, 20) ; 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 1 ms 212 KB Output is correct
5 Correct 1 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 1 ms 212 KB Output is correct
9 Correct 213 ms 22160 KB Output is correct
10 Correct 18 ms 2596 KB Output is correct
11 Correct 115 ms 12064 KB Output is correct
12 Correct 27 ms 3796 KB Output is correct
13 Correct 953 ms 7672 KB Output is correct
14 Correct 10 ms 340 KB Output is correct
15 Correct 17 ms 532 KB Output is correct
16 Correct 219 ms 22188 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 1 ms 212 KB Output is correct
5 Correct 1 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 1 ms 212 KB Output is correct
9 Correct 213 ms 22160 KB Output is correct
10 Correct 18 ms 2596 KB Output is correct
11 Correct 115 ms 12064 KB Output is correct
12 Correct 27 ms 3796 KB Output is correct
13 Correct 953 ms 7672 KB Output is correct
14 Correct 10 ms 340 KB Output is correct
15 Correct 17 ms 532 KB Output is correct
16 Correct 219 ms 22188 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 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 511 ms 45268 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 37 ms 596 KB Output is correct
27 Correct 27 ms 724 KB Output is correct
28 Correct 173 ms 18356 KB Output is correct
29 Correct 268 ms 26840 KB Output is correct
30 Correct 388 ms 35476 KB Output is correct
31 Correct 489 ms 45104 KB Output is correct
32 Correct 0 ms 224 KB Output is correct
33 Correct 1 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 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 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 1 ms 212 KB Output is correct
43 Correct 24 ms 576 KB Output is correct
44 Correct 21 ms 628 KB Output is correct
45 Correct 233 ms 22560 KB Output is correct
46 Correct 362 ms 32164 KB Output is correct
47 Correct 357 ms 32204 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 1 ms 212 KB Output is correct
5 Correct 1 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 1 ms 212 KB Output is correct
9 Correct 213 ms 22160 KB Output is correct
10 Correct 18 ms 2596 KB Output is correct
11 Correct 115 ms 12064 KB Output is correct
12 Correct 27 ms 3796 KB Output is correct
13 Correct 953 ms 7672 KB Output is correct
14 Correct 10 ms 340 KB Output is correct
15 Correct 17 ms 532 KB Output is correct
16 Correct 219 ms 22188 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 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 511 ms 45268 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 37 ms 596 KB Output is correct
27 Correct 27 ms 724 KB Output is correct
28 Correct 173 ms 18356 KB Output is correct
29 Correct 268 ms 26840 KB Output is correct
30 Correct 388 ms 35476 KB Output is correct
31 Correct 489 ms 45104 KB Output is correct
32 Correct 0 ms 224 KB Output is correct
33 Correct 1 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 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 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 1 ms 212 KB Output is correct
43 Correct 24 ms 576 KB Output is correct
44 Correct 21 ms 628 KB Output is correct
45 Correct 233 ms 22560 KB Output is correct
46 Correct 362 ms 32164 KB Output is correct
47 Correct 357 ms 32204 KB Output is correct
48 Correct 0 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 0 ms 212 KB Output is correct
52 Correct 0 ms 212 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 542 ms 44936 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 1640 KB Output is correct
59 Correct 84 ms 1364 KB Output is correct
60 Correct 239 ms 22592 KB Output is correct
61 Correct 340 ms 30464 KB Output is correct
62 Correct 451 ms 37052 KB Output is correct
63 Correct 527 ms 45024 KB Output is correct
64 Correct 1 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 523 ms 44344 KB Output is correct
68 Correct 498 ms 44104 KB Output is correct
69 Correct 485 ms 44004 KB Output is correct
70 Correct 20 ms 724 KB Output is correct
71 Correct 38 ms 1060 KB Output is correct
72 Incorrect 819 ms 9768 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 1 ms 212 KB Output is correct
5 Correct 1 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 1 ms 212 KB Output is correct
9 Correct 213 ms 22160 KB Output is correct
10 Correct 18 ms 2596 KB Output is correct
11 Correct 115 ms 12064 KB Output is correct
12 Correct 27 ms 3796 KB Output is correct
13 Correct 953 ms 7672 KB Output is correct
14 Correct 10 ms 340 KB Output is correct
15 Correct 17 ms 532 KB Output is correct
16 Correct 219 ms 22188 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 551 ms 44120 KB Output is correct
21 Correct 544 ms 44108 KB Output is correct
22 Correct 553 ms 44116 KB Output is correct
23 Correct 425 ms 37736 KB Output is correct
24 Correct 3327 ms 19072 KB Output is correct
25 Correct 3384 ms 19352 KB Output is correct
26 Correct 3325 ms 19376 KB Output is correct
27 Correct 431 ms 44484 KB Output is correct
28 Correct 455 ms 44492 KB Output is correct
29 Correct 583 ms 44424 KB Output is correct
30 Correct 638 ms 44464 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Incorrect 85 ms 1864 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 1 ms 212 KB Output is correct
5 Correct 1 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 1 ms 212 KB Output is correct
9 Correct 213 ms 22160 KB Output is correct
10 Correct 18 ms 2596 KB Output is correct
11 Correct 115 ms 12064 KB Output is correct
12 Correct 27 ms 3796 KB Output is correct
13 Correct 953 ms 7672 KB Output is correct
14 Correct 10 ms 340 KB Output is correct
15 Correct 17 ms 532 KB Output is correct
16 Correct 219 ms 22188 KB Output is correct
17 Correct 542 ms 44168 KB Output is correct
18 Correct 508 ms 44084 KB Output is correct
19 Correct 549 ms 44152 KB Output is correct
20 Correct 648 ms 43912 KB Output is correct
21 Correct 532 ms 38732 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Incorrect 592 ms 4892 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 1 ms 212 KB Output is correct
5 Correct 1 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 1 ms 212 KB Output is correct
9 Correct 213 ms 22160 KB Output is correct
10 Correct 18 ms 2596 KB Output is correct
11 Correct 115 ms 12064 KB Output is correct
12 Correct 27 ms 3796 KB Output is correct
13 Correct 953 ms 7672 KB Output is correct
14 Correct 10 ms 340 KB Output is correct
15 Correct 17 ms 532 KB Output is correct
16 Correct 219 ms 22188 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 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 511 ms 45268 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 37 ms 596 KB Output is correct
27 Correct 27 ms 724 KB Output is correct
28 Correct 173 ms 18356 KB Output is correct
29 Correct 268 ms 26840 KB Output is correct
30 Correct 388 ms 35476 KB Output is correct
31 Correct 489 ms 45104 KB Output is correct
32 Correct 0 ms 224 KB Output is correct
33 Correct 1 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 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 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 1 ms 212 KB Output is correct
43 Correct 24 ms 576 KB Output is correct
44 Correct 21 ms 628 KB Output is correct
45 Correct 233 ms 22560 KB Output is correct
46 Correct 362 ms 32164 KB Output is correct
47 Correct 357 ms 32204 KB Output is correct
48 Correct 0 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 0 ms 212 KB Output is correct
52 Correct 0 ms 212 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 542 ms 44936 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 1640 KB Output is correct
59 Correct 84 ms 1364 KB Output is correct
60 Correct 239 ms 22592 KB Output is correct
61 Correct 340 ms 30464 KB Output is correct
62 Correct 451 ms 37052 KB Output is correct
63 Correct 527 ms 45024 KB Output is correct
64 Correct 1 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 523 ms 44344 KB Output is correct
68 Correct 498 ms 44104 KB Output is correct
69 Correct 485 ms 44004 KB Output is correct
70 Correct 20 ms 724 KB Output is correct
71 Correct 38 ms 1060 KB Output is correct
72 Incorrect 819 ms 9768 KB Solution announced impossible, but it is possible.
73 Halted 0 ms 0 KB -