답안 #553857

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
553857 2022-04-27T07:55:52 Z topovik 분수 공원 (IOI21_parks) C++17
45 / 100
942 ms 79396 KB
#include <bits/stdc++.h>
#include "parks.h"
#define pb push_back
#define f first
#define s second
#define pi acos(-1)

using namespace std;

typedef long long ll;
typedef long double ld;

const ll oo = 1e9;
const ld eps = (ld)1 / oo;
const ll N = 2e5 + 100;
const ll M = 1e6;

const int step[4][2] = {{0, -2}, {0, 2}, {-2, 0}, {2, 0}};

vector <pair<int, int> > ans;
map <int, int> mp[N];
map <int, pair<int, int> > mp1[N];
int pred[N];

//void build(vector <int> u, vector <int> v, vector <int> a, vector <int> b)
//{
//    for (int i = 0; i < u.size(); i++) cout << u[i] << " " << v[i] << " " << a[i] << " " << b[i] << endl;
//}

int get(int x)
{
    return ((pred[x] == x) ? x : (pred[x] = get(pred[x])));
}

void unite(int x, int y)
{
     pred[x] = y;
}

int construct_roads (vector<int> x, vector<int> y) {
    std::vector<int> u, v, a, b;
    int n = x.size();
    vector <pair<int, int> > st;
    for (int i = 0; i < n; i++) mp[x[i]][y[i]] = i + 1;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < 4; j++)
        {
            int x1 = x[i] + step[j][0];
            int y1 = y[i] + step[j][1];
            if (mp[x1][y1] - 1 > i)
            {
                int nx = mp[x1][y1];
                int x2 = (x[i] + x1) / 2;
                int y2 = (y[i] + y1) / 2;
                mp1[x2][y2] = {i + 1, nx};
                for (int c = 0; c < 4; c++)
                {
                    int x3 = x2 + step[c][0] / 2;
                    int y3 = y2 + step[c][1] / 2;
                    if ((x3 & 1) && (y3 & 1)) st.pb({x3, y3});
                }
            }
        }
    }
    sort(st.begin(), st.end());
    reverse(st.begin(), st.end());
    for (int i = 0; i < n; i++) pred[i] = i;
    int kol = n - 1;
    while (!st.empty() && kol > 0)
    {
        pair<int, int> c = st.back();
        st.pop_back();
        int x = c.f, y = c.s;
        for (int i = (((x + y) / 2) & 1) * 2; i <  (((x + y) / 2) & 1) * 2 + 2; i++)
        {
            int x1 = x + step[i][0] / 2;
            int y1 = y + step[i][1] / 2;
            if (mp1[x1].find(y1) != mp1[x1].end())
            {
                c = mp1[x1][y1];
                c.f--, c.s--;
                if (get(c.f) != get(c.s))
                {
                    unite(get(c.f), get(c.s));
                    u.pb(c.f);
                    v.pb(c.s);
                    a.pb(x);
                    b.pb(y);
                    kol--;
                    break;
                }
            }
        }
    }
    if (kol == 0)
    {
        build(u, v, a, b);
        return 1;
    }
    return 0;
}

//int main()
//{
//    int n;
//    cin >> n;
//    vector <int> x(n), y(n);
//    for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
//    cout << construct_roads(x, y) << endl;
//}
/*
1
4
-100000 -100000 100000 -100000 -100000 100000
-100000 -100000 100000 -100000 -100000 100000
-100000 -100000 100000 -100000 -100000 100000
-100000 -100000 100000 -100000 -100000 100000
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 19028 KB Output is correct
2 Correct 10 ms 19052 KB Output is correct
3 Correct 10 ms 19028 KB Output is correct
4 Correct 10 ms 19024 KB Output is correct
5 Correct 11 ms 19100 KB Output is correct
6 Correct 10 ms 19008 KB Output is correct
7 Correct 10 ms 19028 KB Output is correct
8 Correct 9 ms 19100 KB Output is correct
9 Correct 351 ms 48988 KB Output is correct
10 Correct 25 ms 22148 KB Output is correct
11 Correct 107 ms 34976 KB Output is correct
12 Correct 34 ms 23468 KB Output is correct
13 Correct 75 ms 31300 KB Output is correct
14 Correct 11 ms 19284 KB Output is correct
15 Correct 12 ms 19540 KB Output is correct
16 Correct 340 ms 48832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 19028 KB Output is correct
2 Correct 10 ms 19052 KB Output is correct
3 Correct 10 ms 19028 KB Output is correct
4 Correct 10 ms 19024 KB Output is correct
5 Correct 11 ms 19100 KB Output is correct
6 Correct 10 ms 19008 KB Output is correct
7 Correct 10 ms 19028 KB Output is correct
8 Correct 9 ms 19100 KB Output is correct
9 Correct 351 ms 48988 KB Output is correct
10 Correct 25 ms 22148 KB Output is correct
11 Correct 107 ms 34976 KB Output is correct
12 Correct 34 ms 23468 KB Output is correct
13 Correct 75 ms 31300 KB Output is correct
14 Correct 11 ms 19284 KB Output is correct
15 Correct 12 ms 19540 KB Output is correct
16 Correct 340 ms 48832 KB Output is correct
17 Incorrect 10 ms 19028 KB Tree @(3, 3) appears more than once: for edges on positions 1 and 2
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 19028 KB Output is correct
2 Correct 10 ms 19052 KB Output is correct
3 Correct 10 ms 19028 KB Output is correct
4 Correct 10 ms 19024 KB Output is correct
5 Correct 11 ms 19100 KB Output is correct
6 Correct 10 ms 19008 KB Output is correct
7 Correct 10 ms 19028 KB Output is correct
8 Correct 9 ms 19100 KB Output is correct
9 Correct 351 ms 48988 KB Output is correct
10 Correct 25 ms 22148 KB Output is correct
11 Correct 107 ms 34976 KB Output is correct
12 Correct 34 ms 23468 KB Output is correct
13 Correct 75 ms 31300 KB Output is correct
14 Correct 11 ms 19284 KB Output is correct
15 Correct 12 ms 19540 KB Output is correct
16 Correct 340 ms 48832 KB Output is correct
17 Incorrect 10 ms 19028 KB Tree @(3, 3) appears more than once: for edges on positions 1 and 2
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 19028 KB Output is correct
2 Correct 10 ms 19052 KB Output is correct
3 Correct 10 ms 19028 KB Output is correct
4 Correct 10 ms 19024 KB Output is correct
5 Correct 11 ms 19100 KB Output is correct
6 Correct 10 ms 19008 KB Output is correct
7 Correct 10 ms 19028 KB Output is correct
8 Correct 9 ms 19100 KB Output is correct
9 Correct 351 ms 48988 KB Output is correct
10 Correct 25 ms 22148 KB Output is correct
11 Correct 107 ms 34976 KB Output is correct
12 Correct 34 ms 23468 KB Output is correct
13 Correct 75 ms 31300 KB Output is correct
14 Correct 11 ms 19284 KB Output is correct
15 Correct 12 ms 19540 KB Output is correct
16 Correct 340 ms 48832 KB Output is correct
17 Correct 10 ms 19100 KB Output is correct
18 Correct 10 ms 19028 KB Output is correct
19 Correct 10 ms 19080 KB Output is correct
20 Correct 399 ms 70500 KB Output is correct
21 Correct 446 ms 70100 KB Output is correct
22 Correct 487 ms 70064 KB Output is correct
23 Correct 484 ms 70500 KB Output is correct
24 Correct 463 ms 52888 KB Output is correct
25 Correct 715 ms 64536 KB Output is correct
26 Correct 669 ms 64516 KB Output is correct
27 Correct 729 ms 69224 KB Output is correct
28 Correct 694 ms 69300 KB Output is correct
29 Correct 726 ms 69488 KB Output is correct
30 Correct 722 ms 69348 KB Output is correct
31 Correct 10 ms 19028 KB Output is correct
32 Correct 39 ms 22768 KB Output is correct
33 Correct 101 ms 36384 KB Output is correct
34 Correct 410 ms 70528 KB Output is correct
35 Correct 24 ms 21244 KB Output is correct
36 Correct 107 ms 29888 KB Output is correct
37 Correct 246 ms 40952 KB Output is correct
38 Correct 226 ms 38776 KB Output is correct
39 Correct 322 ms 45452 KB Output is correct
40 Correct 451 ms 53852 KB Output is correct
41 Correct 597 ms 60684 KB Output is correct
42 Correct 747 ms 67508 KB Output is correct
43 Correct 9 ms 19028 KB Output is correct
44 Correct 9 ms 19028 KB Output is correct
45 Correct 10 ms 19028 KB Output is correct
46 Correct 10 ms 19028 KB Output is correct
47 Correct 10 ms 19044 KB Output is correct
48 Correct 10 ms 19028 KB Output is correct
49 Correct 10 ms 19104 KB Output is correct
50 Correct 10 ms 19028 KB Output is correct
51 Correct 10 ms 19100 KB Output is correct
52 Correct 9 ms 19028 KB Output is correct
53 Correct 10 ms 19100 KB Output is correct
54 Correct 13 ms 19540 KB Output is correct
55 Correct 14 ms 19740 KB Output is correct
56 Correct 373 ms 45936 KB Output is correct
57 Correct 621 ms 58992 KB Output is correct
58 Correct 634 ms 58840 KB Output is correct
59 Correct 10 ms 19156 KB Output is correct
60 Correct 11 ms 19028 KB Output is correct
61 Correct 10 ms 19060 KB Output is correct
62 Correct 860 ms 73992 KB Output is correct
63 Correct 860 ms 74268 KB Output is correct
64 Correct 856 ms 73944 KB Output is correct
65 Correct 19 ms 19916 KB Output is correct
66 Correct 25 ms 20932 KB Output is correct
67 Correct 368 ms 44840 KB Output is correct
68 Correct 621 ms 58676 KB Output is correct
69 Correct 917 ms 70928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 19028 KB Output is correct
2 Correct 10 ms 19052 KB Output is correct
3 Correct 10 ms 19028 KB Output is correct
4 Correct 10 ms 19024 KB Output is correct
5 Correct 11 ms 19100 KB Output is correct
6 Correct 10 ms 19008 KB Output is correct
7 Correct 10 ms 19028 KB Output is correct
8 Correct 9 ms 19100 KB Output is correct
9 Correct 351 ms 48988 KB Output is correct
10 Correct 25 ms 22148 KB Output is correct
11 Correct 107 ms 34976 KB Output is correct
12 Correct 34 ms 23468 KB Output is correct
13 Correct 75 ms 31300 KB Output is correct
14 Correct 11 ms 19284 KB Output is correct
15 Correct 12 ms 19540 KB Output is correct
16 Correct 340 ms 48832 KB Output is correct
17 Correct 655 ms 79176 KB Output is correct
18 Correct 636 ms 79396 KB Output is correct
19 Correct 443 ms 70060 KB Output is correct
20 Correct 741 ms 67240 KB Output is correct
21 Correct 671 ms 67684 KB Output is correct
22 Correct 9 ms 19028 KB Output is correct
23 Correct 74 ms 27104 KB Output is correct
24 Correct 45 ms 23580 KB Output is correct
25 Correct 157 ms 35252 KB Output is correct
26 Correct 345 ms 45644 KB Output is correct
27 Correct 301 ms 43696 KB Output is correct
28 Correct 459 ms 49764 KB Output is correct
29 Correct 549 ms 56972 KB Output is correct
30 Correct 664 ms 62440 KB Output is correct
31 Correct 800 ms 68416 KB Output is correct
32 Correct 917 ms 72812 KB Output is correct
33 Correct 862 ms 74308 KB Output is correct
34 Correct 19 ms 20348 KB Output is correct
35 Correct 27 ms 21288 KB Output is correct
36 Correct 379 ms 45192 KB Output is correct
37 Correct 697 ms 59108 KB Output is correct
38 Correct 942 ms 71384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 19028 KB Output is correct
2 Correct 10 ms 19052 KB Output is correct
3 Correct 10 ms 19028 KB Output is correct
4 Correct 10 ms 19024 KB Output is correct
5 Correct 11 ms 19100 KB Output is correct
6 Correct 10 ms 19008 KB Output is correct
7 Correct 10 ms 19028 KB Output is correct
8 Correct 9 ms 19100 KB Output is correct
9 Correct 351 ms 48988 KB Output is correct
10 Correct 25 ms 22148 KB Output is correct
11 Correct 107 ms 34976 KB Output is correct
12 Correct 34 ms 23468 KB Output is correct
13 Correct 75 ms 31300 KB Output is correct
14 Correct 11 ms 19284 KB Output is correct
15 Correct 12 ms 19540 KB Output is correct
16 Correct 340 ms 48832 KB Output is correct
17 Incorrect 10 ms 19028 KB Tree @(3, 3) appears more than once: for edges on positions 1 and 2
18 Halted 0 ms 0 KB -