답안 #1033746

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1033746 2024-07-25T04:55:36 Z hotboy2703 분수 공원 (IOI21_parks) C++17
30 / 100
499 ms 31552 KB
#include "parks.h"

#include<bits/stdc++.h>
using ll = int;
using namespace std;
#define pll pair <ll,ll>
#define fi first
#define se second
#define MP make_pair
#define sz(a) (ll((a).size()))
#define MASK(i) (1LL<<(i))
#define BIT(mask,i) (((mask) >> (i))&1)
struct point{
    ll x,y,id;
    point(ll x1 = 0,ll y1 = 0,ll id1 = 0):x(x1),y(y1),id(id1){}
    bool operator < (const point &p)const {
        return MP(x,y) < MP(p.x,p.y);
    }
};
namespace sub1{
    ll solve(vector <ll> x,vector <ll> y){
        for (auto z:x)if (z > 6 || z < 2)return -1;
        ll n = sz(x);
        vector <pll> all[7];
        vector <point> a(n);
        
        for (ll i = 0;i < n;i ++){
            a[i] = {x[i],y[i],i};
        }
        sort(a.begin(),a.end());
        for (ll i = 0;i < n;i ++){
            if (all[a[i].x].empty() || all[a[i].x].back().se + 2 != a[i].y)all[a[i].x].push_back(MP(a[i].y,a[i].y));
            else{
                all[a[i].x].back().se+=2;
            }
        }
        vector <int> U, V, A, B;
        auto add = [&](pll u,pll v, ll x,ll y){
            // cout<<u.fi<<' '<<u.se<<' '<<v.fi<<' '<<v.se<<endl;
            U.push_back((*lower_bound(a.begin(),a.end(),point(u.fi,u.se,0))).id);
            V.push_back((*lower_bound(a.begin(),a.end(),point(v.fi,v.se,0))).id);
            A.push_back(x);
            B.push_back(y);
        };
        for (auto x:all[2]){
            for (ll i = x.fi + 2;i <= x.se;i += 2){
                add(MP(2,i-2),MP(2,i),1,i-1);
            }
        }
        for (auto x:all[4]){
            static ll ptr2 = 0;
            static ll ptr6 = 0;
            vector <ll> sus2,sus6;
            while (ptr2 < sz(all[2]) && all[2][ptr2].se < x.fi)ptr2++;
            while (ptr2 < sz(all[2]) && all[2][ptr2].fi <= x.se){
                // cout<<all[2][ptr2].fi<<' '<<all[2][ptr2].se<<endl;
                pll tmp = all[2][ptr2];
                if (tmp.fi <= x.fi && x.fi <= tmp.se){
                    add(MP(4,x.fi),MP(2,x.fi),3,x.fi-1);
                }
                else if (tmp.fi <= x.se && x.se <= tmp.se){
                    add(MP(4,x.se),MP(2,x.se),3,x.se+1);
                }
                else{
                    sus2.push_back(tmp.fi);
                }
                ptr2++;
            }

            while (ptr6 < sz(all[6]) && all[6][ptr6].se < x.fi)ptr6++;
            while (ptr6 < sz(all[6]) && all[6][ptr6].fi <= x.se){
                pll tmp = all[6][ptr6];
                if (tmp.fi <= x.fi && x.fi <= tmp.se){
                    add(MP(4,x.fi),MP(6,x.fi),5,x.fi-1);
                }
                else if (tmp.fi <= x.se && x.se <= tmp.se){
                    add(MP(4,x.se),MP(6,x.se),5,x.se+1);
                }
                else{
                    sus6.push_back(tmp.fi);
                }
                ptr6++;
            }
            ptr2=0,ptr6=0;
            for (ll j = x.fi + 2;j <= x.se;j += 2){
                while(ptr2 < sz(sus2) && sus2[ptr2]<j)ptr2++; 
                while(ptr6 < sz(sus6) && sus6[ptr6]<j)ptr6++; 
                bool do2,do6;
                do2 =  (ptr2 < sz(sus2) && sus2[ptr2]==j);
                do6 =  (ptr6 < sz(sus6) && sus6[ptr6]==j);
                if (do2 && do6){
                    add(MP(4,j),MP(2,j),3,j-1);
                    add(MP(4,j),MP(6,j),5,j+1);
                    add(MP(4,j),MP(4,j-2),5,j-1);
                    add(MP(4,j),MP(4,j+2),3,j+1);
                    j+=2;
                }
                else if (do2){
                    add(MP(4,j),MP(2,j),3,j-1);
                    add(MP(4,j),MP(4,j-2),5,j-1);
                }
                else if (do6){
                    add(MP(4,j),MP(6,j),5,j-1);
                    add(MP(4,j),MP(4,j-2),3,j-1);
                }
                else add(MP(4,j),MP(4,j-2),3,j-1);
            }
        } 
        for (auto x:all[6]){
            for (ll i = x.fi + 2;i <= x.se;i += 2){
                add(MP(6,i-2),MP(6,i),7,i-1);
            }
        }
        {
            vector <vector <ll > > g(n);
            for (ll i = 0;i < sz(U);i ++){
                g[U[i]].push_back(V[i]);
                g[V[i]].push_back(U[i]);
            }
            vector <bool> in(n);
            queue <ll> q;
            q.push(0);
            in[0] = 1;
            while (!q.empty()){
                ll u = q.front();
                q.pop();
                for (auto v:g[u]){
                    if (!in[v]){
                        in[v] = 1;
                        q.push(v);
                    }
                }
            }
            for (ll i = 0;i < n;i ++)if (!in[i])return 0;
            build(U, V, A, B);
            return 1;
        }
    }
}
int construct_roads(std::vector<int> x, std::vector<int> y) {
    ll tmp = sub1::solve(x,y);
    if (tmp != -1)return tmp;
    ll n = sz(x);
    vector <point> a(n);
    
    for (ll i = 0;i < n;i ++){
        a[i] = {x[i],y[i],i};
    }
    sort(a.begin(),a.end());
    vector <int> U, V, A, B;
    auto add = [&](pll u,pll v, ll x,ll y){
        // cout<<u.fi<<' '<<u.se<<' '<<v.fi<<' '<<v.se<<endl;
        U.push_back((*lower_bound(a.begin(),a.end(),point(u.fi,u.se,0))).id);
        V.push_back((*lower_bound(a.begin(),a.end(),point(v.fi,v.se,0))).id);
        A.push_back(x);
        B.push_back(y);
    };
    vector <pll> last;
    // for (ll i = 0;i < n;i ++)cout<<a[i].x<<' '<<a[i].y<<'\n';
    for (ll i = 0;i < n;i ++){
        // cout<<a[i].x<<' '<<a[i-1].x<<' '<<i<<endl;
        if (i && a[i].x != a[i-1].x+2)return 0;
        ll j = i;
        while (j < n && a[j].x==a[i].x)j++;
        j--;
        vector <pll> all;
        for (ll k = i;k <= j;k ++){
            if (all.empty() || all.back().se + 2 != a[k].y)all.push_back(MP(a[k].y,a[k].y));
            else{
                all.back().se+=2;
            }
        }
        ll ptr = 0;
        for (auto x:all){
            if (ptr)ptr--;
            while (ptr < sz(last) && last[ptr].se < x.fi)ptr++;
            while (ptr < sz(last) && last[ptr].fi <= x.se){
                pll tmp = last[ptr];
                if (tmp.fi <= x.fi && x.fi <= tmp.se){
                    add(MP(a[i].x,x.fi),MP(a[i].x-2,x.fi),a[i].x-1,x.fi-1);
                }
                else if (tmp.fi <= x.se && x.se <= tmp.se){
                    add(MP(a[i].x,x.se),MP(a[i].x-2,x.se),a[i].x-1,x.se+1);
                }
                ptr++;
            }
            for (ll k = x.fi + 2;k <= x.se;k += 2){
                add(MP(a[i].x,k),MP(a[i].x,k-2),a[i].x-1,k-1);
            }
        }
        last = all;
        i=j;
    }
    {
        vector <vector <ll > > g(n);
        for (ll i = 0;i < sz(U);i ++){
            g[U[i]].push_back(V[i]);
            g[V[i]].push_back(U[i]);
        }
        vector <bool> in(n);
        queue <ll> q;
        q.push(0);
        in[0] = 1;
        while (!q.empty()){
            ll u = q.front();
            q.pop();
            for (auto v:g[u]){
                if (!in[v]){
                    in[v] = 1;
                    q.push(v);
                }
            }
        }
        for (ll i = 0;i < n;i ++)if (!in[i])return 0;
        build(U, V, A, B);
        return 1;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 60 ms 14864 KB Output is correct
10 Correct 5 ms 1884 KB Output is correct
11 Correct 31 ms 8148 KB Output is correct
12 Correct 7 ms 2392 KB Output is correct
13 Correct 13 ms 5332 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 59 ms 14776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 60 ms 14864 KB Output is correct
10 Correct 5 ms 1884 KB Output is correct
11 Correct 31 ms 8148 KB Output is correct
12 Correct 7 ms 2392 KB Output is correct
13 Correct 13 ms 5332 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 59 ms 14776 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 122 ms 29456 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 2 ms 860 KB Output is correct
28 Correct 44 ms 11932 KB Output is correct
29 Correct 69 ms 17856 KB Output is correct
30 Correct 94 ms 23724 KB Output is correct
31 Correct 130 ms 29312 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 344 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 141 ms 15036 KB Output is correct
46 Correct 243 ms 21684 KB Output is correct
47 Correct 254 ms 21688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 60 ms 14864 KB Output is correct
10 Correct 5 ms 1884 KB Output is correct
11 Correct 31 ms 8148 KB Output is correct
12 Correct 7 ms 2392 KB Output is correct
13 Correct 13 ms 5332 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 59 ms 14776 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 122 ms 29456 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 2 ms 860 KB Output is correct
28 Correct 44 ms 11932 KB Output is correct
29 Correct 69 ms 17856 KB Output is correct
30 Correct 94 ms 23724 KB Output is correct
31 Correct 130 ms 29312 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 344 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 141 ms 15036 KB Output is correct
46 Correct 243 ms 21684 KB Output is correct
47 Correct 254 ms 21688 KB Output is correct
48 Correct 1 ms 344 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 128 ms 29352 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 1 ms 604 KB Output is correct
58 Correct 3 ms 1300 KB Output is correct
59 Correct 4 ms 1628 KB Output is correct
60 Correct 59 ms 14904 KB Output is correct
61 Correct 78 ms 19968 KB Output is correct
62 Correct 97 ms 24496 KB Output is correct
63 Correct 120 ms 29356 KB Output is correct
64 Correct 0 ms 344 KB Output is correct
65 Correct 0 ms 596 KB Output is correct
66 Correct 1 ms 348 KB Output is correct
67 Correct 118 ms 29344 KB Output is correct
68 Correct 119 ms 29532 KB Output is correct
69 Correct 121 ms 29356 KB Output is correct
70 Correct 2 ms 856 KB Output is correct
71 Correct 4 ms 1332 KB Output is correct
72 Correct 159 ms 15084 KB Output is correct
73 Correct 299 ms 22580 KB Output is correct
74 Correct 499 ms 30008 KB Output is correct
75 Correct 133 ms 31552 KB Output is correct
76 Correct 125 ms 29440 KB Output is correct
77 Correct 3 ms 860 KB Output is correct
78 Correct 4 ms 1304 KB Output is correct
79 Correct 131 ms 15484 KB Output is correct
80 Correct 228 ms 23240 KB Output is correct
81 Correct 391 ms 30788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 60 ms 14864 KB Output is correct
10 Correct 5 ms 1884 KB Output is correct
11 Correct 31 ms 8148 KB Output is correct
12 Correct 7 ms 2392 KB Output is correct
13 Correct 13 ms 5332 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 59 ms 14776 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 138 ms 28824 KB Output is correct
21 Correct 139 ms 28720 KB Output is correct
22 Correct 126 ms 28716 KB Output is correct
23 Correct 107 ms 24400 KB Output is correct
24 Correct 41 ms 7476 KB Output is correct
25 Correct 83 ms 21808 KB Output is correct
26 Correct 39 ms 7472 KB Output is correct
27 Correct 119 ms 27952 KB Output is correct
28 Correct 116 ms 28068 KB Output is correct
29 Correct 124 ms 28336 KB Output is correct
30 Incorrect 85 ms 21868 KB Solution announced impossible, but it is possible.
31 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 60 ms 14864 KB Output is correct
10 Correct 5 ms 1884 KB Output is correct
11 Correct 31 ms 8148 KB Output is correct
12 Correct 7 ms 2392 KB Output is correct
13 Correct 13 ms 5332 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 59 ms 14776 KB Output is correct
17 Correct 128 ms 28316 KB Output is correct
18 Correct 129 ms 28716 KB Output is correct
19 Incorrect 105 ms 22572 KB Solution announced impossible, but it is possible.
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 60 ms 14864 KB Output is correct
10 Correct 5 ms 1884 KB Output is correct
11 Correct 31 ms 8148 KB Output is correct
12 Correct 7 ms 2392 KB Output is correct
13 Correct 13 ms 5332 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 59 ms 14776 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 122 ms 29456 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 2 ms 860 KB Output is correct
28 Correct 44 ms 11932 KB Output is correct
29 Correct 69 ms 17856 KB Output is correct
30 Correct 94 ms 23724 KB Output is correct
31 Correct 130 ms 29312 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 344 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 141 ms 15036 KB Output is correct
46 Correct 243 ms 21684 KB Output is correct
47 Correct 254 ms 21688 KB Output is correct
48 Correct 1 ms 344 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 128 ms 29352 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 1 ms 604 KB Output is correct
58 Correct 3 ms 1300 KB Output is correct
59 Correct 4 ms 1628 KB Output is correct
60 Correct 59 ms 14904 KB Output is correct
61 Correct 78 ms 19968 KB Output is correct
62 Correct 97 ms 24496 KB Output is correct
63 Correct 120 ms 29356 KB Output is correct
64 Correct 0 ms 344 KB Output is correct
65 Correct 0 ms 596 KB Output is correct
66 Correct 1 ms 348 KB Output is correct
67 Correct 118 ms 29344 KB Output is correct
68 Correct 119 ms 29532 KB Output is correct
69 Correct 121 ms 29356 KB Output is correct
70 Correct 2 ms 856 KB Output is correct
71 Correct 4 ms 1332 KB Output is correct
72 Correct 159 ms 15084 KB Output is correct
73 Correct 299 ms 22580 KB Output is correct
74 Correct 499 ms 30008 KB Output is correct
75 Correct 133 ms 31552 KB Output is correct
76 Correct 125 ms 29440 KB Output is correct
77 Correct 3 ms 860 KB Output is correct
78 Correct 4 ms 1304 KB Output is correct
79 Correct 131 ms 15484 KB Output is correct
80 Correct 228 ms 23240 KB Output is correct
81 Correct 391 ms 30788 KB Output is correct
82 Correct 0 ms 348 KB Output is correct
83 Correct 0 ms 348 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 138 ms 28824 KB Output is correct
86 Correct 139 ms 28720 KB Output is correct
87 Correct 126 ms 28716 KB Output is correct
88 Correct 107 ms 24400 KB Output is correct
89 Correct 41 ms 7476 KB Output is correct
90 Correct 83 ms 21808 KB Output is correct
91 Correct 39 ms 7472 KB Output is correct
92 Correct 119 ms 27952 KB Output is correct
93 Correct 116 ms 28068 KB Output is correct
94 Correct 124 ms 28336 KB Output is correct
95 Incorrect 85 ms 21868 KB Solution announced impossible, but it is possible.
96 Halted 0 ms 0 KB -