Submission #551074

# Submission time Handle Problem Language Result Execution time Memory
551074 2022-04-19T18:44:43 Z PiejanVDC Fountain Parks (IOI21_parks) C++17
15 / 100
626 ms 46532 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();
    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[0], s_.y = y[0], s_.dir = 0;
    processed.insert({x[0], y[0]});
    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(mp.count({x + dx[i], y + dy[i]}) && !processed.count({x + dx[i], y + dy[i]})) {
                if(dx[i] == 0) {
                    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(!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)
        return 0;

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

Compilation message

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:44:13: warning: unused variable 'p_' [-Wunused-variable]
   44 |         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 239 ms 22164 KB Output is correct
10 Correct 19 ms 2644 KB Output is correct
11 Correct 112 ms 12036 KB Output is correct
12 Correct 31 ms 3796 KB Output is correct
13 Correct 70 ms 7204 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 208 ms 22136 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 239 ms 22164 KB Output is correct
10 Correct 19 ms 2644 KB Output is correct
11 Correct 112 ms 12036 KB Output is correct
12 Correct 31 ms 3796 KB Output is correct
13 Correct 70 ms 7204 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 208 ms 22136 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 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 491 ms 45240 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 3 ms 596 KB Output is correct
27 Correct 3 ms 724 KB Output is correct
28 Correct 191 ms 18332 KB Output is correct
29 Correct 263 ms 26952 KB Output is correct
30 Correct 412 ms 35640 KB Output is correct
31 Correct 519 ms 45144 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 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 0 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 1 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 2 ms 468 KB Output is correct
44 Correct 2 ms 596 KB Output is correct
45 Correct 254 ms 22416 KB Output is correct
46 Correct 405 ms 33392 KB Output is correct
47 Correct 374 ms 33352 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 239 ms 22164 KB Output is correct
10 Correct 19 ms 2644 KB Output is correct
11 Correct 112 ms 12036 KB Output is correct
12 Correct 31 ms 3796 KB Output is correct
13 Correct 70 ms 7204 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 208 ms 22136 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 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 491 ms 45240 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 3 ms 596 KB Output is correct
27 Correct 3 ms 724 KB Output is correct
28 Correct 191 ms 18332 KB Output is correct
29 Correct 263 ms 26952 KB Output is correct
30 Correct 412 ms 35640 KB Output is correct
31 Correct 519 ms 45144 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 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 0 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 1 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 2 ms 468 KB Output is correct
44 Correct 2 ms 596 KB Output is correct
45 Correct 254 ms 22416 KB Output is correct
46 Correct 405 ms 33392 KB Output is correct
47 Correct 374 ms 33352 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 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 1 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 576 ms 46532 KB Output is correct
56 Incorrect 1 ms 212 KB Solution announced impossible, but it is possible.
57 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 239 ms 22164 KB Output is correct
10 Correct 19 ms 2644 KB Output is correct
11 Correct 112 ms 12036 KB Output is correct
12 Correct 31 ms 3796 KB Output is correct
13 Correct 70 ms 7204 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 208 ms 22136 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 530 ms 44228 KB Output is correct
21 Correct 528 ms 44084 KB Output is correct
22 Correct 574 ms 44116 KB Output is correct
23 Correct 474 ms 37544 KB Output is correct
24 Correct 207 ms 19024 KB Output is correct
25 Correct 155 ms 19012 KB Output is correct
26 Correct 155 ms 19032 KB Output is correct
27 Correct 543 ms 44144 KB Output is correct
28 Correct 466 ms 44064 KB Output is correct
29 Correct 610 ms 45760 KB Output is correct
30 Correct 592 ms 45748 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Incorrect 11 ms 1748 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 239 ms 22164 KB Output is correct
10 Correct 19 ms 2644 KB Output is correct
11 Correct 112 ms 12036 KB Output is correct
12 Correct 31 ms 3796 KB Output is correct
13 Correct 70 ms 7204 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 208 ms 22136 KB Output is correct
17 Correct 516 ms 44152 KB Output is correct
18 Correct 506 ms 44112 KB Output is correct
19 Correct 540 ms 44108 KB Output is correct
20 Correct 626 ms 45696 KB Output is correct
21 Correct 491 ms 40172 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Incorrect 47 ms 5392 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 239 ms 22164 KB Output is correct
10 Correct 19 ms 2644 KB Output is correct
11 Correct 112 ms 12036 KB Output is correct
12 Correct 31 ms 3796 KB Output is correct
13 Correct 70 ms 7204 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 208 ms 22136 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 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 491 ms 45240 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 3 ms 596 KB Output is correct
27 Correct 3 ms 724 KB Output is correct
28 Correct 191 ms 18332 KB Output is correct
29 Correct 263 ms 26952 KB Output is correct
30 Correct 412 ms 35640 KB Output is correct
31 Correct 519 ms 45144 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 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 0 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 1 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 2 ms 468 KB Output is correct
44 Correct 2 ms 596 KB Output is correct
45 Correct 254 ms 22416 KB Output is correct
46 Correct 405 ms 33392 KB Output is correct
47 Correct 374 ms 33352 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 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 1 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 576 ms 46532 KB Output is correct
56 Incorrect 1 ms 212 KB Solution announced impossible, but it is possible.
57 Halted 0 ms 0 KB -