답안 #553004

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
553004 2022-04-24T12:26:47 Z PiejanVDC 분수 공원 (IOI21_parks) C++17
15 / 100
2268 ms 46572 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 AA = 0 ; AA < min(n, 15) ; AA++) {
        int A = AA * 15 + 343 + 5;
        A %= n;
        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:47:17: warning: unused variable 'p_' [-Wunused-variable]
   47 |             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 215 ms 22212 KB Output is correct
10 Correct 22 ms 2600 KB Output is correct
11 Correct 118 ms 12004 KB Output is correct
12 Correct 28 ms 3792 KB Output is correct
13 Correct 720 ms 7364 KB Output is correct
14 Correct 10 ms 340 KB Output is correct
15 Correct 13 ms 532 KB Output is correct
16 Correct 237 ms 22180 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 215 ms 22212 KB Output is correct
10 Correct 22 ms 2600 KB Output is correct
11 Correct 118 ms 12004 KB Output is correct
12 Correct 28 ms 3792 KB Output is correct
13 Correct 720 ms 7364 KB Output is correct
14 Correct 10 ms 340 KB Output is correct
15 Correct 13 ms 532 KB Output is correct
16 Correct 237 ms 22180 KB Output is correct
17 Correct 0 ms 308 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 552 ms 44544 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 36 ms 596 KB Output is correct
27 Correct 21 ms 744 KB Output is correct
28 Correct 167 ms 18328 KB Output is correct
29 Correct 372 ms 26956 KB Output is correct
30 Correct 417 ms 36340 KB Output is correct
31 Correct 507 ms 44480 KB Output is correct
32 Correct 1 ms 212 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 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 0 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 20 ms 580 KB Output is correct
44 Correct 18 ms 640 KB Output is correct
45 Correct 250 ms 22288 KB Output is correct
46 Correct 365 ms 32460 KB Output is correct
47 Correct 390 ms 32384 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 215 ms 22212 KB Output is correct
10 Correct 22 ms 2600 KB Output is correct
11 Correct 118 ms 12004 KB Output is correct
12 Correct 28 ms 3792 KB Output is correct
13 Correct 720 ms 7364 KB Output is correct
14 Correct 10 ms 340 KB Output is correct
15 Correct 13 ms 532 KB Output is correct
16 Correct 237 ms 22180 KB Output is correct
17 Correct 0 ms 308 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 552 ms 44544 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 36 ms 596 KB Output is correct
27 Correct 21 ms 744 KB Output is correct
28 Correct 167 ms 18328 KB Output is correct
29 Correct 372 ms 26956 KB Output is correct
30 Correct 417 ms 36340 KB Output is correct
31 Correct 507 ms 44480 KB Output is correct
32 Correct 1 ms 212 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 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 0 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 20 ms 580 KB Output is correct
44 Correct 18 ms 640 KB Output is correct
45 Correct 250 ms 22288 KB Output is correct
46 Correct 365 ms 32460 KB Output is correct
47 Correct 390 ms 32384 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 1 ms 212 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 607 ms 44892 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
57 Correct 3 ms 596 KB Output is correct
58 Correct 14 ms 1652 KB Output is correct
59 Correct 66 ms 1424 KB Output is correct
60 Correct 235 ms 22388 KB Output is correct
61 Correct 370 ms 30024 KB Output is correct
62 Correct 467 ms 37108 KB Output is correct
63 Correct 583 ms 44912 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 491 ms 44180 KB Output is correct
68 Correct 497 ms 44272 KB Output is correct
69 Correct 538 ms 43856 KB Output is correct
70 Correct 16 ms 596 KB Output is correct
71 Correct 33 ms 980 KB Output is correct
72 Incorrect 686 ms 9720 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 215 ms 22212 KB Output is correct
10 Correct 22 ms 2600 KB Output is correct
11 Correct 118 ms 12004 KB Output is correct
12 Correct 28 ms 3792 KB Output is correct
13 Correct 720 ms 7364 KB Output is correct
14 Correct 10 ms 340 KB Output is correct
15 Correct 13 ms 532 KB Output is correct
16 Correct 237 ms 22180 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 549 ms 44048 KB Output is correct
21 Correct 531 ms 44124 KB Output is correct
22 Correct 515 ms 44108 KB Output is correct
23 Correct 439 ms 37604 KB Output is correct
24 Correct 2268 ms 19160 KB Output is correct
25 Correct 2188 ms 19244 KB Output is correct
26 Correct 2171 ms 19176 KB Output is correct
27 Correct 454 ms 44128 KB Output is correct
28 Correct 431 ms 44236 KB Output is correct
29 Correct 635 ms 44228 KB Output is correct
30 Correct 648 ms 44096 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Incorrect 77 ms 1672 KB Solution announced impossible, but it is possible.
33 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 215 ms 22212 KB Output is correct
10 Correct 22 ms 2600 KB Output is correct
11 Correct 118 ms 12004 KB Output is correct
12 Correct 28 ms 3792 KB Output is correct
13 Correct 720 ms 7364 KB Output is correct
14 Correct 10 ms 340 KB Output is correct
15 Correct 13 ms 532 KB Output is correct
16 Correct 237 ms 22180 KB Output is correct
17 Correct 625 ms 44084 KB Output is correct
18 Correct 557 ms 44208 KB Output is correct
19 Correct 608 ms 44088 KB Output is correct
20 Correct 1247 ms 46572 KB Output is correct
21 Correct 490 ms 38768 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Incorrect 374 ms 5020 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 215 ms 22212 KB Output is correct
10 Correct 22 ms 2600 KB Output is correct
11 Correct 118 ms 12004 KB Output is correct
12 Correct 28 ms 3792 KB Output is correct
13 Correct 720 ms 7364 KB Output is correct
14 Correct 10 ms 340 KB Output is correct
15 Correct 13 ms 532 KB Output is correct
16 Correct 237 ms 22180 KB Output is correct
17 Correct 0 ms 308 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 552 ms 44544 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 36 ms 596 KB Output is correct
27 Correct 21 ms 744 KB Output is correct
28 Correct 167 ms 18328 KB Output is correct
29 Correct 372 ms 26956 KB Output is correct
30 Correct 417 ms 36340 KB Output is correct
31 Correct 507 ms 44480 KB Output is correct
32 Correct 1 ms 212 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 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 0 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 20 ms 580 KB Output is correct
44 Correct 18 ms 640 KB Output is correct
45 Correct 250 ms 22288 KB Output is correct
46 Correct 365 ms 32460 KB Output is correct
47 Correct 390 ms 32384 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 1 ms 212 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 607 ms 44892 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
57 Correct 3 ms 596 KB Output is correct
58 Correct 14 ms 1652 KB Output is correct
59 Correct 66 ms 1424 KB Output is correct
60 Correct 235 ms 22388 KB Output is correct
61 Correct 370 ms 30024 KB Output is correct
62 Correct 467 ms 37108 KB Output is correct
63 Correct 583 ms 44912 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 491 ms 44180 KB Output is correct
68 Correct 497 ms 44272 KB Output is correct
69 Correct 538 ms 43856 KB Output is correct
70 Correct 16 ms 596 KB Output is correct
71 Correct 33 ms 980 KB Output is correct
72 Incorrect 686 ms 9720 KB Solution announced impossible, but it is possible.
73 Halted 0 ms 0 KB -