답안 #552998

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
552998 2022-04-24T12:22:34 Z PiejanVDC 분수 공원 (IOI21_parks) C++17
15 / 100
3500 ms 45588 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, 32) ; 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;
      |                 ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 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 228 ms 22172 KB Output is correct
10 Correct 18 ms 2644 KB Output is correct
11 Correct 116 ms 12108 KB Output is correct
12 Correct 28 ms 3788 KB Output is correct
13 Correct 1530 ms 7292 KB Output is correct
14 Correct 18 ms 428 KB Output is correct
15 Correct 31 ms 492 KB Output is correct
16 Correct 249 ms 22404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 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 228 ms 22172 KB Output is correct
10 Correct 18 ms 2644 KB Output is correct
11 Correct 116 ms 12108 KB Output is correct
12 Correct 28 ms 3788 KB Output is correct
13 Correct 1530 ms 7292 KB Output is correct
14 Correct 18 ms 428 KB Output is correct
15 Correct 31 ms 492 KB Output is correct
16 Correct 249 ms 22404 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 1 ms 212 KB Output is correct
21 Correct 1 ms 300 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 548 ms 45588 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 58 ms 724 KB Output is correct
27 Correct 46 ms 752 KB Output is correct
28 Correct 183 ms 18504 KB Output is correct
29 Correct 342 ms 27076 KB Output is correct
30 Correct 501 ms 35744 KB Output is correct
31 Correct 613 ms 45512 KB Output is correct
32 Correct 1 ms 300 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 300 KB Output is correct
35 Correct 1 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 300 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 304 KB Output is correct
43 Correct 45 ms 468 KB Output is correct
44 Correct 41 ms 568 KB Output is correct
45 Correct 285 ms 22616 KB Output is correct
46 Correct 419 ms 32424 KB Output is correct
47 Correct 405 ms 32404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 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 228 ms 22172 KB Output is correct
10 Correct 18 ms 2644 KB Output is correct
11 Correct 116 ms 12108 KB Output is correct
12 Correct 28 ms 3788 KB Output is correct
13 Correct 1530 ms 7292 KB Output is correct
14 Correct 18 ms 428 KB Output is correct
15 Correct 31 ms 492 KB Output is correct
16 Correct 249 ms 22404 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 1 ms 212 KB Output is correct
21 Correct 1 ms 300 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 548 ms 45588 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 58 ms 724 KB Output is correct
27 Correct 46 ms 752 KB Output is correct
28 Correct 183 ms 18504 KB Output is correct
29 Correct 342 ms 27076 KB Output is correct
30 Correct 501 ms 35744 KB Output is correct
31 Correct 613 ms 45512 KB Output is correct
32 Correct 1 ms 300 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 300 KB Output is correct
35 Correct 1 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 300 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 304 KB Output is correct
43 Correct 45 ms 468 KB Output is correct
44 Correct 41 ms 568 KB Output is correct
45 Correct 285 ms 22616 KB Output is correct
46 Correct 419 ms 32424 KB Output is correct
47 Correct 405 ms 32404 KB Output is correct
48 Correct 2 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 1 ms 212 KB Output is correct
52 Correct 1 ms 300 KB Output is correct
53 Correct 1 ms 300 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 589 ms 45296 KB Output is correct
56 Correct 1 ms 304 KB Output is correct
57 Correct 3 ms 724 KB Output is correct
58 Correct 11 ms 1728 KB Output is correct
59 Correct 130 ms 1520 KB Output is correct
60 Correct 224 ms 22908 KB Output is correct
61 Correct 345 ms 30896 KB Output is correct
62 Correct 431 ms 37596 KB Output is correct
63 Correct 527 ms 45328 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
65 Correct 1 ms 300 KB Output is correct
66 Correct 0 ms 300 KB Output is correct
67 Correct 497 ms 44500 KB Output is correct
68 Correct 498 ms 44480 KB Output is correct
69 Correct 496 ms 44240 KB Output is correct
70 Correct 28 ms 620 KB Output is correct
71 Correct 59 ms 1136 KB Output is correct
72 Incorrect 1373 ms 10460 KB Solution announced impossible, but it is possible.
73 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 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 228 ms 22172 KB Output is correct
10 Correct 18 ms 2644 KB Output is correct
11 Correct 116 ms 12108 KB Output is correct
12 Correct 28 ms 3788 KB Output is correct
13 Correct 1530 ms 7292 KB Output is correct
14 Correct 18 ms 428 KB Output is correct
15 Correct 31 ms 492 KB Output is correct
16 Correct 249 ms 22404 KB Output is correct
17 Correct 0 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 511 ms 44648 KB Output is correct
21 Correct 491 ms 44584 KB Output is correct
22 Correct 501 ms 44588 KB Output is correct
23 Correct 389 ms 38040 KB Output is correct
24 Execution timed out 3540 ms 19440 KB Time limit exceeded
25 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 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 228 ms 22172 KB Output is correct
10 Correct 18 ms 2644 KB Output is correct
11 Correct 116 ms 12108 KB Output is correct
12 Correct 28 ms 3788 KB Output is correct
13 Correct 1530 ms 7292 KB Output is correct
14 Correct 18 ms 428 KB Output is correct
15 Correct 31 ms 492 KB Output is correct
16 Correct 249 ms 22404 KB Output is correct
17 Correct 489 ms 44588 KB Output is correct
18 Correct 467 ms 44720 KB Output is correct
19 Correct 491 ms 44772 KB Output is correct
20 Correct 568 ms 44268 KB Output is correct
21 Correct 482 ms 39052 KB Output is correct
22 Correct 0 ms 304 KB Output is correct
23 Incorrect 812 ms 5276 KB Solution announced impossible, but it is possible.
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 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 228 ms 22172 KB Output is correct
10 Correct 18 ms 2644 KB Output is correct
11 Correct 116 ms 12108 KB Output is correct
12 Correct 28 ms 3788 KB Output is correct
13 Correct 1530 ms 7292 KB Output is correct
14 Correct 18 ms 428 KB Output is correct
15 Correct 31 ms 492 KB Output is correct
16 Correct 249 ms 22404 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 1 ms 212 KB Output is correct
21 Correct 1 ms 300 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 548 ms 45588 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 58 ms 724 KB Output is correct
27 Correct 46 ms 752 KB Output is correct
28 Correct 183 ms 18504 KB Output is correct
29 Correct 342 ms 27076 KB Output is correct
30 Correct 501 ms 35744 KB Output is correct
31 Correct 613 ms 45512 KB Output is correct
32 Correct 1 ms 300 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 300 KB Output is correct
35 Correct 1 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 300 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 304 KB Output is correct
43 Correct 45 ms 468 KB Output is correct
44 Correct 41 ms 568 KB Output is correct
45 Correct 285 ms 22616 KB Output is correct
46 Correct 419 ms 32424 KB Output is correct
47 Correct 405 ms 32404 KB Output is correct
48 Correct 2 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 1 ms 212 KB Output is correct
52 Correct 1 ms 300 KB Output is correct
53 Correct 1 ms 300 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 589 ms 45296 KB Output is correct
56 Correct 1 ms 304 KB Output is correct
57 Correct 3 ms 724 KB Output is correct
58 Correct 11 ms 1728 KB Output is correct
59 Correct 130 ms 1520 KB Output is correct
60 Correct 224 ms 22908 KB Output is correct
61 Correct 345 ms 30896 KB Output is correct
62 Correct 431 ms 37596 KB Output is correct
63 Correct 527 ms 45328 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
65 Correct 1 ms 300 KB Output is correct
66 Correct 0 ms 300 KB Output is correct
67 Correct 497 ms 44500 KB Output is correct
68 Correct 498 ms 44480 KB Output is correct
69 Correct 496 ms 44240 KB Output is correct
70 Correct 28 ms 620 KB Output is correct
71 Correct 59 ms 1136 KB Output is correct
72 Incorrect 1373 ms 10460 KB Solution announced impossible, but it is possible.
73 Halted 0 ms 0 KB -