답안 #1050636

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1050636 2024-08-09T12:01:12 Z Malix 분수 공원 (IOI21_parks) C++17
30 / 100
1361 ms 89260 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(used[{x[i]-1,min(y[i],y[i]+loc[j].S)+1}]==1&&used[{x[i]+1,min(y[i],y[i]+loc[j].S)+1}]==1)return 0;
                if(used[{x[i]-1,min(y[i],y[i]+loc[j].S)+1}]==1){
                    used[{x[i]+1,min(y[i],y[i]+loc[j].S)+1}]=1;
                    ans[2].PB(x[i]+1);
                    ans[3].PB(min(y[i],y[i]+loc[j].S)+1);
                }
                else{
                    used[{x[i]-1,min(y[i],y[i]+loc[j].S)+1}]=1;
                    ans[2].PB(x[i]-1);
                    ans[3].PB(min(y[i],y[i]+loc[j].S)+1);
                }
            }
            else{
                if(used[{min(x[i],x[i]+loc[j].F)+1,y[i]-1}]==1&&used[{min(x[i],x[i]+loc[j].F)+1,y[i]+1}]==1)return 0;
                if(used[{min(x[i],x[i]+loc[j].F)+1,y[i]-1}]==1){
                    used[{min(x[i],x[i]+loc[j].F)+1,y[i]+1}]=1;
                    ans[2].PB(min(x[i],x[i]+loc[j].F)+1);
                    ans[3].PB(y[i]+1);
                }
                else{
                    used[{min(x[i],x[i]+loc[j].F)+1,y[i]-1}]=1;
                    ans[2].PB(min(x[i],x[i]+loc[j].F)+1);
                    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 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 436 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 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 31 ms 8940 KB Output is correct
10 Correct 3 ms 1292 KB Output is correct
11 Correct 13 ms 4996 KB Output is correct
12 Correct 5 ms 1604 KB Output is correct
13 Correct 5 ms 2548 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 30 ms 8916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 436 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 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 31 ms 8940 KB Output is correct
10 Correct 3 ms 1292 KB Output is correct
11 Correct 13 ms 4996 KB Output is correct
12 Correct 5 ms 1604 KB Output is correct
13 Correct 5 ms 2548 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 30 ms 8916 KB Output is correct
17 Correct 35 ms 12816 KB Output is correct
18 Correct 35 ms 12880 KB Output is correct
19 Correct 34 ms 12832 KB Output is correct
20 Correct 45 ms 12880 KB Output is correct
21 Correct 40 ms 12880 KB Output is correct
22 Correct 35 ms 12868 KB Output is correct
23 Correct 591 ms 56280 KB Output is correct
24 Correct 39 ms 12892 KB Output is correct
25 Correct 42 ms 13200 KB Output is correct
26 Correct 40 ms 13396 KB Output is correct
27 Correct 39 ms 13648 KB Output is correct
28 Correct 222 ms 30396 KB Output is correct
29 Correct 378 ms 39084 KB Output is correct
30 Correct 488 ms 47784 KB Output is correct
31 Correct 606 ms 56192 KB Output is correct
32 Correct 35 ms 12880 KB Output is correct
33 Correct 35 ms 12884 KB Output is correct
34 Correct 35 ms 12876 KB Output is correct
35 Correct 35 ms 12884 KB Output is correct
36 Correct 39 ms 12884 KB Output is correct
37 Correct 37 ms 12764 KB Output is correct
38 Correct 36 ms 12776 KB Output is correct
39 Correct 36 ms 12752 KB Output is correct
40 Correct 39 ms 12840 KB Output is correct
41 Correct 37 ms 12888 KB Output is correct
42 Correct 36 ms 12700 KB Output is correct
43 Correct 46 ms 13140 KB Output is correct
44 Correct 41 ms 13396 KB Output is correct
45 Correct 295 ms 32436 KB Output is correct
46 Correct 468 ms 40804 KB Output is correct
47 Correct 406 ms 40864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 436 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 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 31 ms 8940 KB Output is correct
10 Correct 3 ms 1292 KB Output is correct
11 Correct 13 ms 4996 KB Output is correct
12 Correct 5 ms 1604 KB Output is correct
13 Correct 5 ms 2548 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 30 ms 8916 KB Output is correct
17 Correct 35 ms 12816 KB Output is correct
18 Correct 35 ms 12880 KB Output is correct
19 Correct 34 ms 12832 KB Output is correct
20 Correct 45 ms 12880 KB Output is correct
21 Correct 40 ms 12880 KB Output is correct
22 Correct 35 ms 12868 KB Output is correct
23 Correct 591 ms 56280 KB Output is correct
24 Correct 39 ms 12892 KB Output is correct
25 Correct 42 ms 13200 KB Output is correct
26 Correct 40 ms 13396 KB Output is correct
27 Correct 39 ms 13648 KB Output is correct
28 Correct 222 ms 30396 KB Output is correct
29 Correct 378 ms 39084 KB Output is correct
30 Correct 488 ms 47784 KB Output is correct
31 Correct 606 ms 56192 KB Output is correct
32 Correct 35 ms 12880 KB Output is correct
33 Correct 35 ms 12884 KB Output is correct
34 Correct 35 ms 12876 KB Output is correct
35 Correct 35 ms 12884 KB Output is correct
36 Correct 39 ms 12884 KB Output is correct
37 Correct 37 ms 12764 KB Output is correct
38 Correct 36 ms 12776 KB Output is correct
39 Correct 36 ms 12752 KB Output is correct
40 Correct 39 ms 12840 KB Output is correct
41 Correct 37 ms 12888 KB Output is correct
42 Correct 36 ms 12700 KB Output is correct
43 Correct 46 ms 13140 KB Output is correct
44 Correct 41 ms 13396 KB Output is correct
45 Correct 295 ms 32436 KB Output is correct
46 Correct 468 ms 40804 KB Output is correct
47 Correct 406 ms 40864 KB Output is correct
48 Correct 58 ms 19024 KB Output is correct
49 Correct 67 ms 19032 KB Output is correct
50 Correct 58 ms 19168 KB Output is correct
51 Correct 63 ms 19024 KB Output is correct
52 Correct 66 ms 19192 KB Output is correct
53 Correct 65 ms 19196 KB Output is correct
54 Correct 69 ms 19196 KB Output is correct
55 Correct 657 ms 70308 KB Output is correct
56 Correct 60 ms 19024 KB Output is correct
57 Correct 66 ms 19604 KB Output is correct
58 Correct 93 ms 20820 KB Output is correct
59 Correct 75 ms 21332 KB Output is correct
60 Correct 330 ms 44732 KB Output is correct
61 Correct 474 ms 53668 KB Output is correct
62 Correct 626 ms 61604 KB Output is correct
63 Correct 684 ms 70312 KB Output is correct
64 Correct 58 ms 19024 KB Output is correct
65 Correct 58 ms 19024 KB Output is correct
66 Correct 57 ms 19028 KB Output is correct
67 Correct 626 ms 70208 KB Output is correct
68 Correct 658 ms 70328 KB Output is correct
69 Correct 626 ms 69964 KB Output is correct
70 Correct 90 ms 20048 KB Output is correct
71 Correct 75 ms 20780 KB Output is correct
72 Correct 358 ms 44940 KB Output is correct
73 Correct 514 ms 57764 KB Output is correct
74 Correct 711 ms 70308 KB Output is correct
75 Correct 627 ms 70308 KB Output is correct
76 Correct 622 ms 70308 KB Output is correct
77 Correct 70 ms 20308 KB Output is correct
78 Correct 74 ms 21080 KB Output is correct
79 Correct 334 ms 44980 KB Output is correct
80 Correct 527 ms 57668 KB Output is correct
81 Correct 704 ms 70308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 436 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 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 31 ms 8940 KB Output is correct
10 Correct 3 ms 1292 KB Output is correct
11 Correct 13 ms 4996 KB Output is correct
12 Correct 5 ms 1604 KB Output is correct
13 Correct 5 ms 2548 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 30 ms 8916 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 Incorrect 212 ms 42920 KB Solution announced impossible, but it is possible.
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 436 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 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 31 ms 8940 KB Output is correct
10 Correct 3 ms 1292 KB Output is correct
11 Correct 13 ms 4996 KB Output is correct
12 Correct 5 ms 1604 KB Output is correct
13 Correct 5 ms 2548 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 30 ms 8916 KB Output is correct
17 Correct 1361 ms 89260 KB Output is correct
18 Incorrect 812 ms 69424 KB Solution announced impossible, but it is possible.
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 436 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 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 31 ms 8940 KB Output is correct
10 Correct 3 ms 1292 KB Output is correct
11 Correct 13 ms 4996 KB Output is correct
12 Correct 5 ms 1604 KB Output is correct
13 Correct 5 ms 2548 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 30 ms 8916 KB Output is correct
17 Correct 35 ms 12816 KB Output is correct
18 Correct 35 ms 12880 KB Output is correct
19 Correct 34 ms 12832 KB Output is correct
20 Correct 45 ms 12880 KB Output is correct
21 Correct 40 ms 12880 KB Output is correct
22 Correct 35 ms 12868 KB Output is correct
23 Correct 591 ms 56280 KB Output is correct
24 Correct 39 ms 12892 KB Output is correct
25 Correct 42 ms 13200 KB Output is correct
26 Correct 40 ms 13396 KB Output is correct
27 Correct 39 ms 13648 KB Output is correct
28 Correct 222 ms 30396 KB Output is correct
29 Correct 378 ms 39084 KB Output is correct
30 Correct 488 ms 47784 KB Output is correct
31 Correct 606 ms 56192 KB Output is correct
32 Correct 35 ms 12880 KB Output is correct
33 Correct 35 ms 12884 KB Output is correct
34 Correct 35 ms 12876 KB Output is correct
35 Correct 35 ms 12884 KB Output is correct
36 Correct 39 ms 12884 KB Output is correct
37 Correct 37 ms 12764 KB Output is correct
38 Correct 36 ms 12776 KB Output is correct
39 Correct 36 ms 12752 KB Output is correct
40 Correct 39 ms 12840 KB Output is correct
41 Correct 37 ms 12888 KB Output is correct
42 Correct 36 ms 12700 KB Output is correct
43 Correct 46 ms 13140 KB Output is correct
44 Correct 41 ms 13396 KB Output is correct
45 Correct 295 ms 32436 KB Output is correct
46 Correct 468 ms 40804 KB Output is correct
47 Correct 406 ms 40864 KB Output is correct
48 Correct 58 ms 19024 KB Output is correct
49 Correct 67 ms 19032 KB Output is correct
50 Correct 58 ms 19168 KB Output is correct
51 Correct 63 ms 19024 KB Output is correct
52 Correct 66 ms 19192 KB Output is correct
53 Correct 65 ms 19196 KB Output is correct
54 Correct 69 ms 19196 KB Output is correct
55 Correct 657 ms 70308 KB Output is correct
56 Correct 60 ms 19024 KB Output is correct
57 Correct 66 ms 19604 KB Output is correct
58 Correct 93 ms 20820 KB Output is correct
59 Correct 75 ms 21332 KB Output is correct
60 Correct 330 ms 44732 KB Output is correct
61 Correct 474 ms 53668 KB Output is correct
62 Correct 626 ms 61604 KB Output is correct
63 Correct 684 ms 70312 KB Output is correct
64 Correct 58 ms 19024 KB Output is correct
65 Correct 58 ms 19024 KB Output is correct
66 Correct 57 ms 19028 KB Output is correct
67 Correct 626 ms 70208 KB Output is correct
68 Correct 658 ms 70328 KB Output is correct
69 Correct 626 ms 69964 KB Output is correct
70 Correct 90 ms 20048 KB Output is correct
71 Correct 75 ms 20780 KB Output is correct
72 Correct 358 ms 44940 KB Output is correct
73 Correct 514 ms 57764 KB Output is correct
74 Correct 711 ms 70308 KB Output is correct
75 Correct 627 ms 70308 KB Output is correct
76 Correct 622 ms 70308 KB Output is correct
77 Correct 70 ms 20308 KB Output is correct
78 Correct 74 ms 21080 KB Output is correct
79 Correct 334 ms 44980 KB Output is correct
80 Correct 527 ms 57668 KB Output is correct
81 Correct 704 ms 70308 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 Incorrect 212 ms 42920 KB Solution announced impossible, but it is possible.
86 Halted 0 ms 0 KB -