답안 #1050673

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1050673 2024-08-09T12:20:23 Z Malix 분수 공원 (IOI21_parks) C++17
30 / 100
1294 ms 77756 KB
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pi;
typedef vector<pi> pii;
typedef tuple<int,int,int> tii;

#define REP(i,a,b) for(int i=a;i<b;i++)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define LSOne(s) ((s)&(-s))

ll INF=1e18+10;
int inf=1e9+10;
ll M=1e9+7;

map<pi,pi> p;
map<pi,int> s,num,used;

pi parent(pi x){
    if(p[x]==x)return x;
    return p[x]=parent(p[x]);
}

void join(pi x,pi y){
    x=parent(x);
    y=parent(y);
    if(x==y)return;
    if(s[x]<s[y])swap(x,y);
    s[x]+=s[y];
    p[y]=x;
}

int construct_roads(std::vector<int> x, std::vector<int> y) {
    int n=x.size();
    int mx=0;
    REP(i,0,n)mx=max(mx,x[i]);
if(mx==2){
    pii a;
    REP(i,0,n)a.PB({y[i],i});
    sort(a.begin(),a.end());
    vii ans(4);
    REP(i,0,n-1){
        if(a[i].F+2!=a[i+1].F)return 0;
        ans[0].PB(a[i].S);
        ans[1].PB(a[i+1].S);
        ans[2].PB(3);
        ans[3].PB(a[i].F+1);
    }
    build(ans[0],ans[1],ans[2],ans[3]);
    return 1;
}
if(mx==4){
    REP(i,0,n)s[{x[i],y[i]}]=1;
    REP(i,0,n)p[{x[i],y[i]}]={x[i],y[i]};
    REP(i,0,n)num[{x[i],y[i]}]=i;
    vii ans(4);
    REP(i,2,5){
        REP(j,2,200001){
            if(j<200000&&s[{i,j}]>0&&s[{i,j+2}]>0){
                join({i,j},{i,j+2});
                ans[0].PB(num[{i,j}]);
                ans[1].PB(num[{i,j+2}]);
                if(i==2)ans[2].PB(i-1);
                else ans[2].PB(i+1);
                ans[3].PB(j+1);
            }
            if(i==2&&s[{i,j}]>0&&s[{i+2,j}]>0){
                join({i,j},{i+2,j});
                ans[0].PB(num[{i,j}]);
                ans[1].PB(num[{i+2,j}]);
                ans[2].PB(i+1);
                ans[3].PB(j-1);
            }
            j++;
        }
        i++;
    }
    pi t=parent({x[0],y[0]});
    bool flag=1;
    REP(i,0,n)if(parent({x[i],y[i]})!=t)flag=0;
    if(flag){
        build(ans[0],ans[1],ans[2],ans[3]);
        return 1;
    }
    return 0;
}
if(mx==6){
    REP(i,0,n)s[{x[i],y[i]}]=1;
    REP(i,0,n)p[{x[i],y[i]}]={x[i],y[i]};
    REP(i,0,n)num[{x[i],y[i]}]=i;
    vii ans(4);
    REP(i,2,7){
        REP(j,2,200000){
            if(s[{i,j}]>0&&s[{i,j+2}]>0){
                join({i,j},{i,j+2});
                ans[0].PB(num[{i,j}]);
                ans[1].PB(num[{i,j+2}]);
                if(i==2)ans[2].PB(i-1);
                else if(i==6)ans[2].PB(i+1);
                else if(i==4){
                    if((j/2)%2==0)ans[2].PB(i+1);
                    else ans[2].PB(i-1);
                }
                ans[3].PB(j+1);
                used[{ans[2].back(),ans[3].back()}]=1;
            }
            j++;
        }
        i++;
    }
    REP(i,2,5){
        REP(j,2,200001){
            if(s[{i,j}]>0&&s[{i+2,j}]>0&&parent({i,j})!=parent({i+2,j})){
                if(used[{i+1,j-1}]==1&&used[{i+1,j+1}])return 0;
                join({i,j},{i+2,j});
                ans[0].PB(num[{i,j}]);
                ans[1].PB(num[{i+2,j}]);
                if(used[{i+1,j-1}]==1){
                    ans[2].PB(i+1);
                    ans[3].PB(j+1);
                }
                else{
                    ans[2].PB(i+1);
                    ans[3].PB(j-1);
                }
            }
            j++;
        }
        i++;
    }
    pi t=parent({x[0],y[0]});
    bool flag=1;
    REP(i,0,n)if(parent({x[i],y[i]})!=t)flag=0;
    if(flag){
        build(ans[0],ans[1],ans[2],ans[3]);
        return 1;
    }
    return 0;
}
    REP(i,0,n)s[{x[i],y[i]}]=1;
    REP(i,0,n)p[{x[i],y[i]}]={x[i],y[i]};
    REP(i,0,n)num[{x[i],y[i]}]=i;
    vii ans(4);
    pii loc={{0,2},{0,-2},{2,0},{-2,0}};
    REP(i,0,n){
        REP(j,0,4)if(s[{x[i]+loc[j].F,y[i]+loc[j].S}]>0&&parent({x[i],y[i]})!=parent({x[i]+loc[j].F,y[i]+loc[j].S})){
            join({x[i],y[i]},{x[i]+loc[j].F,y[i]+loc[j].S});
            ans[0].PB(num[{x[i],y[i]}]);
            ans[1].PB(num[{x[i]+loc[j].F,y[i]+loc[j].S}]);
            if(loc[j].F==0){
                if((min(y[i],y[i]+loc[j].S)/2)%2==1)ans[2].PB(x[i]+1);
                else ans[2].PB(x[i]-1);
                ans[3].PB(min(y[i],y[i]+loc[j].S)+1);
            }
            else{
                ans[2].PB(min(x[i],x[i]+loc[j].F)+1);
                if((min(x[i],x[i]+loc[j].F)/2)%2==1)ans[3].PB(y[i]-1);
                else ans[3].PB(y[i]+1);
            }
        }
    }
    pi t=parent({x[0],y[0]});
    bool flag=1;
    REP(i,0,n)if(parent({x[i],y[i]})!=t)flag=0;
    if(flag){
        build(ans[0],ans[1],ans[2],ans[3]);
        return 1;
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 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 0 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 37 ms 9088 KB Output is correct
10 Correct 3 ms 1272 KB Output is correct
11 Correct 16 ms 4908 KB Output is correct
12 Correct 5 ms 1764 KB Output is correct
13 Correct 5 ms 2516 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 35 ms 9044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 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 0 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 37 ms 9088 KB Output is correct
10 Correct 3 ms 1272 KB Output is correct
11 Correct 16 ms 4908 KB Output is correct
12 Correct 5 ms 1764 KB Output is correct
13 Correct 5 ms 2516 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 35 ms 9044 KB Output is correct
17 Correct 43 ms 12808 KB Output is correct
18 Correct 37 ms 12812 KB Output is correct
19 Correct 37 ms 12748 KB Output is correct
20 Correct 42 ms 12808 KB Output is correct
21 Correct 46 ms 12792 KB Output is correct
22 Correct 39 ms 12916 KB Output is correct
23 Correct 641 ms 57008 KB Output is correct
24 Correct 38 ms 12888 KB Output is correct
25 Correct 45 ms 13184 KB Output is correct
26 Correct 42 ms 13392 KB Output is correct
27 Correct 45 ms 13648 KB Output is correct
28 Correct 241 ms 30396 KB Output is correct
29 Correct 343 ms 39336 KB Output is correct
30 Correct 497 ms 48040 KB Output is correct
31 Correct 608 ms 56988 KB Output is correct
32 Correct 36 ms 12884 KB Output is correct
33 Correct 35 ms 12892 KB Output is correct
34 Correct 35 ms 12808 KB Output is correct
35 Correct 35 ms 12824 KB Output is correct
36 Correct 40 ms 12880 KB Output is correct
37 Correct 35 ms 12884 KB Output is correct
38 Correct 36 ms 12884 KB Output is correct
39 Correct 35 ms 12908 KB Output is correct
40 Correct 35 ms 12892 KB Output is correct
41 Correct 36 ms 12880 KB Output is correct
42 Correct 39 ms 12888 KB Output is correct
43 Correct 38 ms 13148 KB Output is correct
44 Correct 41 ms 13400 KB Output is correct
45 Correct 289 ms 32484 KB Output is correct
46 Correct 394 ms 41356 KB Output is correct
47 Correct 405 ms 41384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 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 0 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 37 ms 9088 KB Output is correct
10 Correct 3 ms 1272 KB Output is correct
11 Correct 16 ms 4908 KB Output is correct
12 Correct 5 ms 1764 KB Output is correct
13 Correct 5 ms 2516 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 35 ms 9044 KB Output is correct
17 Correct 43 ms 12808 KB Output is correct
18 Correct 37 ms 12812 KB Output is correct
19 Correct 37 ms 12748 KB Output is correct
20 Correct 42 ms 12808 KB Output is correct
21 Correct 46 ms 12792 KB Output is correct
22 Correct 39 ms 12916 KB Output is correct
23 Correct 641 ms 57008 KB Output is correct
24 Correct 38 ms 12888 KB Output is correct
25 Correct 45 ms 13184 KB Output is correct
26 Correct 42 ms 13392 KB Output is correct
27 Correct 45 ms 13648 KB Output is correct
28 Correct 241 ms 30396 KB Output is correct
29 Correct 343 ms 39336 KB Output is correct
30 Correct 497 ms 48040 KB Output is correct
31 Correct 608 ms 56988 KB Output is correct
32 Correct 36 ms 12884 KB Output is correct
33 Correct 35 ms 12892 KB Output is correct
34 Correct 35 ms 12808 KB Output is correct
35 Correct 35 ms 12824 KB Output is correct
36 Correct 40 ms 12880 KB Output is correct
37 Correct 35 ms 12884 KB Output is correct
38 Correct 36 ms 12884 KB Output is correct
39 Correct 35 ms 12908 KB Output is correct
40 Correct 35 ms 12892 KB Output is correct
41 Correct 36 ms 12880 KB Output is correct
42 Correct 39 ms 12888 KB Output is correct
43 Correct 38 ms 13148 KB Output is correct
44 Correct 41 ms 13400 KB Output is correct
45 Correct 289 ms 32484 KB Output is correct
46 Correct 394 ms 41356 KB Output is correct
47 Correct 405 ms 41384 KB Output is correct
48 Correct 63 ms 19028 KB Output is correct
49 Correct 58 ms 18988 KB Output is correct
50 Correct 59 ms 19120 KB Output is correct
51 Correct 59 ms 19200 KB Output is correct
52 Correct 58 ms 19028 KB Output is correct
53 Correct 62 ms 19016 KB Output is correct
54 Correct 62 ms 19084 KB Output is correct
55 Correct 694 ms 70820 KB Output is correct
56 Correct 60 ms 19024 KB Output is correct
57 Correct 65 ms 19540 KB Output is correct
58 Correct 71 ms 20820 KB Output is correct
59 Correct 84 ms 21336 KB Output is correct
60 Correct 354 ms 44984 KB Output is correct
61 Correct 458 ms 53828 KB Output is correct
62 Correct 570 ms 61864 KB Output is correct
63 Correct 687 ms 70820 KB Output is correct
64 Correct 57 ms 19124 KB Output is correct
65 Correct 59 ms 19012 KB Output is correct
66 Correct 60 ms 19024 KB Output is correct
67 Correct 615 ms 70924 KB Output is correct
68 Correct 604 ms 70780 KB Output is correct
69 Correct 618 ms 70616 KB Output is correct
70 Correct 70 ms 20048 KB Output is correct
71 Correct 83 ms 20820 KB Output is correct
72 Correct 331 ms 44984 KB Output is correct
73 Correct 533 ms 58248 KB Output is correct
74 Correct 699 ms 70912 KB Output is correct
75 Correct 711 ms 70744 KB Output is correct
76 Correct 608 ms 70872 KB Output is correct
77 Correct 71 ms 20304 KB Output is correct
78 Correct 75 ms 21072 KB Output is correct
79 Correct 336 ms 44984 KB Output is correct
80 Correct 541 ms 57932 KB Output is correct
81 Correct 712 ms 70820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 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 0 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 37 ms 9088 KB Output is correct
10 Correct 3 ms 1272 KB Output is correct
11 Correct 16 ms 4908 KB Output is correct
12 Correct 5 ms 1764 KB Output is correct
13 Correct 5 ms 2516 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 35 ms 9044 KB Output is correct
17 Correct 1 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 Incorrect 1165 ms 65584 KB Tree @(174445, 25559) appears more than once: for edges on positions 6 and 7
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 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 0 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 37 ms 9088 KB Output is correct
10 Correct 3 ms 1272 KB Output is correct
11 Correct 16 ms 4908 KB Output is correct
12 Correct 5 ms 1764 KB Output is correct
13 Correct 5 ms 2516 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 35 ms 9044 KB Output is correct
17 Correct 1294 ms 77480 KB Output is correct
18 Correct 1267 ms 77756 KB Output is correct
19 Incorrect 1191 ms 65296 KB Tree @(29283, 20721) appears more than once: for edges on positions 2 and 3
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 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 0 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 37 ms 9088 KB Output is correct
10 Correct 3 ms 1272 KB Output is correct
11 Correct 16 ms 4908 KB Output is correct
12 Correct 5 ms 1764 KB Output is correct
13 Correct 5 ms 2516 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 35 ms 9044 KB Output is correct
17 Correct 43 ms 12808 KB Output is correct
18 Correct 37 ms 12812 KB Output is correct
19 Correct 37 ms 12748 KB Output is correct
20 Correct 42 ms 12808 KB Output is correct
21 Correct 46 ms 12792 KB Output is correct
22 Correct 39 ms 12916 KB Output is correct
23 Correct 641 ms 57008 KB Output is correct
24 Correct 38 ms 12888 KB Output is correct
25 Correct 45 ms 13184 KB Output is correct
26 Correct 42 ms 13392 KB Output is correct
27 Correct 45 ms 13648 KB Output is correct
28 Correct 241 ms 30396 KB Output is correct
29 Correct 343 ms 39336 KB Output is correct
30 Correct 497 ms 48040 KB Output is correct
31 Correct 608 ms 56988 KB Output is correct
32 Correct 36 ms 12884 KB Output is correct
33 Correct 35 ms 12892 KB Output is correct
34 Correct 35 ms 12808 KB Output is correct
35 Correct 35 ms 12824 KB Output is correct
36 Correct 40 ms 12880 KB Output is correct
37 Correct 35 ms 12884 KB Output is correct
38 Correct 36 ms 12884 KB Output is correct
39 Correct 35 ms 12908 KB Output is correct
40 Correct 35 ms 12892 KB Output is correct
41 Correct 36 ms 12880 KB Output is correct
42 Correct 39 ms 12888 KB Output is correct
43 Correct 38 ms 13148 KB Output is correct
44 Correct 41 ms 13400 KB Output is correct
45 Correct 289 ms 32484 KB Output is correct
46 Correct 394 ms 41356 KB Output is correct
47 Correct 405 ms 41384 KB Output is correct
48 Correct 63 ms 19028 KB Output is correct
49 Correct 58 ms 18988 KB Output is correct
50 Correct 59 ms 19120 KB Output is correct
51 Correct 59 ms 19200 KB Output is correct
52 Correct 58 ms 19028 KB Output is correct
53 Correct 62 ms 19016 KB Output is correct
54 Correct 62 ms 19084 KB Output is correct
55 Correct 694 ms 70820 KB Output is correct
56 Correct 60 ms 19024 KB Output is correct
57 Correct 65 ms 19540 KB Output is correct
58 Correct 71 ms 20820 KB Output is correct
59 Correct 84 ms 21336 KB Output is correct
60 Correct 354 ms 44984 KB Output is correct
61 Correct 458 ms 53828 KB Output is correct
62 Correct 570 ms 61864 KB Output is correct
63 Correct 687 ms 70820 KB Output is correct
64 Correct 57 ms 19124 KB Output is correct
65 Correct 59 ms 19012 KB Output is correct
66 Correct 60 ms 19024 KB Output is correct
67 Correct 615 ms 70924 KB Output is correct
68 Correct 604 ms 70780 KB Output is correct
69 Correct 618 ms 70616 KB Output is correct
70 Correct 70 ms 20048 KB Output is correct
71 Correct 83 ms 20820 KB Output is correct
72 Correct 331 ms 44984 KB Output is correct
73 Correct 533 ms 58248 KB Output is correct
74 Correct 699 ms 70912 KB Output is correct
75 Correct 711 ms 70744 KB Output is correct
76 Correct 608 ms 70872 KB Output is correct
77 Correct 71 ms 20304 KB Output is correct
78 Correct 75 ms 21072 KB Output is correct
79 Correct 336 ms 44984 KB Output is correct
80 Correct 541 ms 57932 KB Output is correct
81 Correct 712 ms 70820 KB Output is correct
82 Correct 1 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 Incorrect 1165 ms 65584 KB Tree @(174445, 25559) appears more than once: for edges on positions 6 and 7
86 Halted 0 ms 0 KB -