답안 #1092282

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1092282 2024-09-23T16:58:36 Z TlenekWodoru 분수 공원 (IOI21_parks) C++17
55 / 100
998 ms 126796 KB
#include<bits/stdc++.h>
#include "parks.h"
using namespace std;
struct Edge
{
    int som,ind;
};
map<pair<int,int>,int>M,M2;
vector<Edge>Graf[200009];
vector<int>D[1000009];
pair<int,int>KimJest[1000009];
bool zaj[1000009];
vector<int>Sprz;
int g[1000009];
int match[1000009];
int n,m=0,k=0,N,IleVert=0;
int f[200009],ilosc[200009];
int F(int v)
{
    if(f[v]==v){return v;}
    return f[v]=F(f[v]);
}
void Polacz(int a, int b)
{
    a=F(a);
    b=F(b);
    if(a==b){return;}
    if(ilosc[a]<ilosc[b]){swap(a,b);}
    ilosc[a]+=ilosc[b];
    f[b]=a;
}
bool DFS(int v)
{
    if(zaj[v]){return 0;}
    zaj[v]=1;
    Sprz.push_back(v);
    for(int som : D[v])
    {
        if(match[som]==-1||DFS(match[som]))
        {
            match[v]=som;
            match[som]=v;
            return 1;
        }
    }
    return 0;
}
void SKOJ()
{
    random_shuffle(g,g+N);
    for(int i=0;i<N;i++)
    {
        zaj[i]=0;
    }
    for(int i=0;i<N;i++)
    {
        int a=g[i];
        for(int b : D[a])
        {
            if(match[a]==-1&&match[b]==-1)
            {
                match[a]=b;
                match[b]=a;
            }
        }
    }
    random_shuffle(g,g+N);
    for(int i=0;i<N;i++)
    {
        int u=g[i];
        if(match[u]==-1)
        {
            DFS(u);
        }
        for(int temp : Sprz)
        {
            zaj[temp]=0;
        }
        Sprz.clear();
    }
}
void CzySpojna(int v)
{
    zaj[v]=1;
    IleVert++;
    for(auto[som,ind] : Graf[v])
    {
        if(zaj[som]){continue;}
        CzySpojna(som);
    }
}
int construct_roads(vector<int>X, vector<int>Y)
{
    srand(2137);
    n=(int)X.size();
    for(int i=0;i<n;i++)
    {
        M[{X[i],Y[i]}]=i;
    }
    for(int i=0;i<n;i++)
    {
        if(M.find({X[i]-2,Y[i]})!=M.end())
        {
            Graf[i].push_back({M[{X[i]-2,Y[i]}],m});
            Graf[M[{X[i]-2,Y[i]}]].push_back({i,m});
            m++;
        }
        if(M.find({X[i],Y[i]-2})!=M.end())
        {
            Graf[i].push_back({M[{X[i],Y[i]-2}],m});
            Graf[M[{X[i],Y[i]-2}]].push_back({i,m});
            m++;
        }
    }
    CzySpojna(0);
    if(IleVert!=n){return 0;}
    vector<pair<int,int>>E(m);
    for(int i=0;i<n;i++)
    {
        for(auto[som,ind] : Graf[i])
        {
            int a=i,b=som;
            if(pair<int,int>{X[a],Y[a]}>pair<int,int>{X[b],Y[b]}){continue;}
            E[ind]={a,b};
        }
    }
    for(int i=0;i<(int)E.size();i++)
    {
        const int a=E[i].first,b=E[i].second;
        vector<pair<int,int>>Som;
        if(Y[a]+2==Y[b])
        {
            Som.push_back({X[a]-1,Y[a]+1});
            Som.push_back({X[a]+1,Y[a]+1});
        }
        else if(X[a]+2==X[b])
        {
            Som.push_back({X[a]+1,Y[a]+1});
            Som.push_back({X[a]+1,Y[a]-1});
        }
        for(pair<int,int>som : Som)
        {
            if(M2.find(som)==M2.end())
            {
                KimJest[k]=som;
                M2[som]=k++;
            }
            int u=m+M2[som];
            D[i].push_back(u);
            D[u].push_back(i);
        }
    }
    N=m+k;
    for(int i=0;i<N;i++){match[i]=-1;}
for(int I=1;I<=1;I++)
{
    for(int i=0;i<N;i++){g[i]=i;}
    SKOJ();
    for(int i=0;i<n;i++)
    {
        f[i]=i;
        ilosc[i]=1;
    }
    for(int i=0;i<n;i++)
    {
        for(auto[som,ind] : Graf[i])
        {
            if(match[ind]==-1){continue;}
            Polacz(i,som);
        }
    }
    if(ilosc[F(0)]==n)
    {
        vector<int>O1,O2,O3,O4;
        for(int j=0;j<m;j++)
        {
            const int a=E[j].first,b=E[j].second;
            if(match[j]!=-1)
            {
                pair<int,int>xd=KimJest[match[j]-m];
                O1.push_back(a);
                O2.push_back(b);
                O3.push_back(xd.first);
                O4.push_back(xd.second);
            }
        }
        build(O1,O2,O3,O4);
        return 1;
    }
    vector<int>U;
    for(int i=0;i<n;i++){g[i]=i;}
    random_shuffle(g,g+n);
    for(int i=0;i<n;i++)
    {
        const int u=g[i];
        for(auto[som,ind] : Graf[u])
        {
            if(match[ind]==-1&&F(u)!=F(som))
            {
                U.push_back(ind);
            }
        }
    }
    random_shuffle(U.begin(),U.end());
    for(int i=0;i<N;i++){match[i]=-1;}
    for(int u : U)
    {
        for(int som : D[u])
        {
            if(match[u]==-1&&match[som]==-1)
            {
                match[u]=som;
                match[som]=u;
            }
        }
    }
}
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 28504 KB Output is correct
2 Correct 13 ms 28508 KB Output is correct
3 Correct 11 ms 28508 KB Output is correct
4 Correct 11 ms 28504 KB Output is correct
5 Correct 11 ms 28504 KB Output is correct
6 Correct 12 ms 28508 KB Output is correct
7 Correct 12 ms 28504 KB Output is correct
8 Correct 12 ms 28508 KB Output is correct
9 Correct 303 ms 75828 KB Output is correct
10 Correct 27 ms 33628 KB Output is correct
11 Correct 115 ms 54224 KB Output is correct
12 Correct 35 ms 35920 KB Output is correct
13 Correct 38 ms 34640 KB Output is correct
14 Correct 12 ms 28760 KB Output is correct
15 Correct 13 ms 28764 KB Output is correct
16 Correct 286 ms 74572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 28504 KB Output is correct
2 Correct 13 ms 28508 KB Output is correct
3 Correct 11 ms 28508 KB Output is correct
4 Correct 11 ms 28504 KB Output is correct
5 Correct 11 ms 28504 KB Output is correct
6 Correct 12 ms 28508 KB Output is correct
7 Correct 12 ms 28504 KB Output is correct
8 Correct 12 ms 28508 KB Output is correct
9 Correct 303 ms 75828 KB Output is correct
10 Correct 27 ms 33628 KB Output is correct
11 Correct 115 ms 54224 KB Output is correct
12 Correct 35 ms 35920 KB Output is correct
13 Correct 38 ms 34640 KB Output is correct
14 Correct 12 ms 28760 KB Output is correct
15 Correct 13 ms 28764 KB Output is correct
16 Correct 286 ms 74572 KB Output is correct
17 Correct 11 ms 28508 KB Output is correct
18 Correct 11 ms 28508 KB Output is correct
19 Correct 11 ms 28636 KB Output is correct
20 Correct 11 ms 28508 KB Output is correct
21 Correct 11 ms 28600 KB Output is correct
22 Correct 13 ms 28508 KB Output is correct
23 Correct 998 ms 126796 KB Output is correct
24 Correct 11 ms 28508 KB Output is correct
25 Correct 13 ms 29156 KB Output is correct
26 Correct 13 ms 29020 KB Output is correct
27 Correct 14 ms 29064 KB Output is correct
28 Correct 307 ms 67412 KB Output is correct
29 Correct 496 ms 87624 KB Output is correct
30 Correct 752 ms 107220 KB Output is correct
31 Correct 962 ms 125636 KB Output is correct
32 Correct 13 ms 28508 KB Output is correct
33 Correct 12 ms 28548 KB Output is correct
34 Correct 12 ms 28636 KB Output is correct
35 Correct 12 ms 28508 KB Output is correct
36 Correct 12 ms 28508 KB Output is correct
37 Correct 12 ms 28508 KB Output is correct
38 Correct 12 ms 28508 KB Output is correct
39 Correct 14 ms 28508 KB Output is correct
40 Correct 12 ms 28508 KB Output is correct
41 Correct 12 ms 28508 KB Output is correct
42 Correct 11 ms 28616 KB Output is correct
43 Correct 13 ms 28764 KB Output is correct
44 Correct 14 ms 28832 KB Output is correct
45 Correct 297 ms 68280 KB Output is correct
46 Correct 493 ms 86348 KB Output is correct
47 Correct 464 ms 86100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 28504 KB Output is correct
2 Correct 13 ms 28508 KB Output is correct
3 Correct 11 ms 28508 KB Output is correct
4 Correct 11 ms 28504 KB Output is correct
5 Correct 11 ms 28504 KB Output is correct
6 Correct 12 ms 28508 KB Output is correct
7 Correct 12 ms 28504 KB Output is correct
8 Correct 12 ms 28508 KB Output is correct
9 Correct 303 ms 75828 KB Output is correct
10 Correct 27 ms 33628 KB Output is correct
11 Correct 115 ms 54224 KB Output is correct
12 Correct 35 ms 35920 KB Output is correct
13 Correct 38 ms 34640 KB Output is correct
14 Correct 12 ms 28760 KB Output is correct
15 Correct 13 ms 28764 KB Output is correct
16 Correct 286 ms 74572 KB Output is correct
17 Correct 11 ms 28508 KB Output is correct
18 Correct 11 ms 28508 KB Output is correct
19 Correct 11 ms 28636 KB Output is correct
20 Correct 11 ms 28508 KB Output is correct
21 Correct 11 ms 28600 KB Output is correct
22 Correct 13 ms 28508 KB Output is correct
23 Correct 998 ms 126796 KB Output is correct
24 Correct 11 ms 28508 KB Output is correct
25 Correct 13 ms 29156 KB Output is correct
26 Correct 13 ms 29020 KB Output is correct
27 Correct 14 ms 29064 KB Output is correct
28 Correct 307 ms 67412 KB Output is correct
29 Correct 496 ms 87624 KB Output is correct
30 Correct 752 ms 107220 KB Output is correct
31 Correct 962 ms 125636 KB Output is correct
32 Correct 13 ms 28508 KB Output is correct
33 Correct 12 ms 28548 KB Output is correct
34 Correct 12 ms 28636 KB Output is correct
35 Correct 12 ms 28508 KB Output is correct
36 Correct 12 ms 28508 KB Output is correct
37 Correct 12 ms 28508 KB Output is correct
38 Correct 12 ms 28508 KB Output is correct
39 Correct 14 ms 28508 KB Output is correct
40 Correct 12 ms 28508 KB Output is correct
41 Correct 12 ms 28508 KB Output is correct
42 Correct 11 ms 28616 KB Output is correct
43 Correct 13 ms 28764 KB Output is correct
44 Correct 14 ms 28832 KB Output is correct
45 Correct 297 ms 68280 KB Output is correct
46 Correct 493 ms 86348 KB Output is correct
47 Correct 464 ms 86100 KB Output is correct
48 Correct 13 ms 28760 KB Output is correct
49 Correct 11 ms 28788 KB Output is correct
50 Correct 15 ms 28508 KB Output is correct
51 Correct 12 ms 28636 KB Output is correct
52 Correct 12 ms 28508 KB Output is correct
53 Correct 12 ms 28508 KB Output is correct
54 Correct 12 ms 28508 KB Output is correct
55 Incorrect 986 ms 105928 KB Solution announced impossible, but it is possible.
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 28504 KB Output is correct
2 Correct 13 ms 28508 KB Output is correct
3 Correct 11 ms 28508 KB Output is correct
4 Correct 11 ms 28504 KB Output is correct
5 Correct 11 ms 28504 KB Output is correct
6 Correct 12 ms 28508 KB Output is correct
7 Correct 12 ms 28504 KB Output is correct
8 Correct 12 ms 28508 KB Output is correct
9 Correct 303 ms 75828 KB Output is correct
10 Correct 27 ms 33628 KB Output is correct
11 Correct 115 ms 54224 KB Output is correct
12 Correct 35 ms 35920 KB Output is correct
13 Correct 38 ms 34640 KB Output is correct
14 Correct 12 ms 28760 KB Output is correct
15 Correct 13 ms 28764 KB Output is correct
16 Correct 286 ms 74572 KB Output is correct
17 Correct 13 ms 28508 KB Output is correct
18 Correct 13 ms 28632 KB Output is correct
19 Correct 12 ms 28508 KB Output is correct
20 Correct 692 ms 108616 KB Output is correct
21 Correct 770 ms 101952 KB Output is correct
22 Correct 680 ms 101580 KB Output is correct
23 Correct 595 ms 107484 KB Output is correct
24 Correct 173 ms 45928 KB Output is correct
25 Correct 298 ms 52252 KB Output is correct
26 Correct 301 ms 52448 KB Output is correct
27 Correct 768 ms 116904 KB Output is correct
28 Correct 739 ms 116932 KB Output is correct
29 Correct 761 ms 116876 KB Output is correct
30 Correct 809 ms 116908 KB Output is correct
31 Correct 12 ms 28504 KB Output is correct
32 Correct 44 ms 34388 KB Output is correct
33 Correct 83 ms 37576 KB Output is correct
34 Correct 754 ms 107080 KB Output is correct
35 Correct 20 ms 29784 KB Output is correct
36 Correct 67 ms 34804 KB Output is correct
37 Correct 135 ms 41304 KB Output is correct
38 Correct 230 ms 57528 KB Output is correct
39 Correct 327 ms 68308 KB Output is correct
40 Correct 451 ms 79212 KB Output is correct
41 Correct 583 ms 90028 KB Output is correct
42 Correct 760 ms 100784 KB Output is correct
43 Correct 13 ms 28504 KB Output is correct
44 Correct 12 ms 28508 KB Output is correct
45 Correct 12 ms 28508 KB Output is correct
46 Correct 13 ms 28500 KB Output is correct
47 Correct 12 ms 28632 KB Output is correct
48 Correct 12 ms 28508 KB Output is correct
49 Correct 11 ms 28508 KB Output is correct
50 Correct 12 ms 28532 KB Output is correct
51 Correct 13 ms 28508 KB Output is correct
52 Correct 12 ms 28588 KB Output is correct
53 Correct 13 ms 28508 KB Output is correct
54 Correct 14 ms 28900 KB Output is correct
55 Correct 14 ms 28860 KB Output is correct
56 Correct 295 ms 68236 KB Output is correct
57 Correct 468 ms 86212 KB Output is correct
58 Correct 460 ms 86188 KB Output is correct
59 Correct 15 ms 28504 KB Output is correct
60 Correct 15 ms 28508 KB Output is correct
61 Correct 12 ms 28508 KB Output is correct
62 Correct 719 ms 121484 KB Output is correct
63 Correct 742 ms 121496 KB Output is correct
64 Correct 707 ms 121740 KB Output is correct
65 Correct 20 ms 29016 KB Output is correct
66 Correct 17 ms 29532 KB Output is correct
67 Correct 315 ms 66900 KB Output is correct
68 Correct 597 ms 86928 KB Output is correct
69 Correct 804 ms 105208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 28504 KB Output is correct
2 Correct 13 ms 28508 KB Output is correct
3 Correct 11 ms 28508 KB Output is correct
4 Correct 11 ms 28504 KB Output is correct
5 Correct 11 ms 28504 KB Output is correct
6 Correct 12 ms 28508 KB Output is correct
7 Correct 12 ms 28504 KB Output is correct
8 Correct 12 ms 28508 KB Output is correct
9 Correct 303 ms 75828 KB Output is correct
10 Correct 27 ms 33628 KB Output is correct
11 Correct 115 ms 54224 KB Output is correct
12 Correct 35 ms 35920 KB Output is correct
13 Correct 38 ms 34640 KB Output is correct
14 Correct 12 ms 28760 KB Output is correct
15 Correct 13 ms 28764 KB Output is correct
16 Correct 286 ms 74572 KB Output is correct
17 Correct 813 ms 123740 KB Output is correct
18 Correct 831 ms 123208 KB Output is correct
19 Correct 937 ms 102084 KB Output is correct
20 Correct 923 ms 110056 KB Output is correct
21 Correct 747 ms 105468 KB Output is correct
22 Correct 11 ms 28448 KB Output is correct
23 Correct 98 ms 40876 KB Output is correct
24 Correct 32 ms 31212 KB Output is correct
25 Correct 132 ms 37880 KB Output is correct
26 Correct 210 ms 44376 KB Output is correct
27 Correct 353 ms 69052 KB Output is correct
28 Correct 517 ms 79532 KB Output is correct
29 Correct 626 ms 89300 KB Output is correct
30 Correct 786 ms 99460 KB Output is correct
31 Correct 861 ms 109740 KB Output is correct
32 Correct 952 ms 116896 KB Output is correct
33 Correct 821 ms 123352 KB Output is correct
34 Correct 15 ms 29276 KB Output is correct
35 Correct 19 ms 29788 KB Output is correct
36 Correct 383 ms 69324 KB Output is correct
37 Correct 624 ms 90152 KB Output is correct
38 Correct 874 ms 110536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 28504 KB Output is correct
2 Correct 13 ms 28508 KB Output is correct
3 Correct 11 ms 28508 KB Output is correct
4 Correct 11 ms 28504 KB Output is correct
5 Correct 11 ms 28504 KB Output is correct
6 Correct 12 ms 28508 KB Output is correct
7 Correct 12 ms 28504 KB Output is correct
8 Correct 12 ms 28508 KB Output is correct
9 Correct 303 ms 75828 KB Output is correct
10 Correct 27 ms 33628 KB Output is correct
11 Correct 115 ms 54224 KB Output is correct
12 Correct 35 ms 35920 KB Output is correct
13 Correct 38 ms 34640 KB Output is correct
14 Correct 12 ms 28760 KB Output is correct
15 Correct 13 ms 28764 KB Output is correct
16 Correct 286 ms 74572 KB Output is correct
17 Correct 11 ms 28508 KB Output is correct
18 Correct 11 ms 28508 KB Output is correct
19 Correct 11 ms 28636 KB Output is correct
20 Correct 11 ms 28508 KB Output is correct
21 Correct 11 ms 28600 KB Output is correct
22 Correct 13 ms 28508 KB Output is correct
23 Correct 998 ms 126796 KB Output is correct
24 Correct 11 ms 28508 KB Output is correct
25 Correct 13 ms 29156 KB Output is correct
26 Correct 13 ms 29020 KB Output is correct
27 Correct 14 ms 29064 KB Output is correct
28 Correct 307 ms 67412 KB Output is correct
29 Correct 496 ms 87624 KB Output is correct
30 Correct 752 ms 107220 KB Output is correct
31 Correct 962 ms 125636 KB Output is correct
32 Correct 13 ms 28508 KB Output is correct
33 Correct 12 ms 28548 KB Output is correct
34 Correct 12 ms 28636 KB Output is correct
35 Correct 12 ms 28508 KB Output is correct
36 Correct 12 ms 28508 KB Output is correct
37 Correct 12 ms 28508 KB Output is correct
38 Correct 12 ms 28508 KB Output is correct
39 Correct 14 ms 28508 KB Output is correct
40 Correct 12 ms 28508 KB Output is correct
41 Correct 12 ms 28508 KB Output is correct
42 Correct 11 ms 28616 KB Output is correct
43 Correct 13 ms 28764 KB Output is correct
44 Correct 14 ms 28832 KB Output is correct
45 Correct 297 ms 68280 KB Output is correct
46 Correct 493 ms 86348 KB Output is correct
47 Correct 464 ms 86100 KB Output is correct
48 Correct 13 ms 28760 KB Output is correct
49 Correct 11 ms 28788 KB Output is correct
50 Correct 15 ms 28508 KB Output is correct
51 Correct 12 ms 28636 KB Output is correct
52 Correct 12 ms 28508 KB Output is correct
53 Correct 12 ms 28508 KB Output is correct
54 Correct 12 ms 28508 KB Output is correct
55 Incorrect 986 ms 105928 KB Solution announced impossible, but it is possible.
56 Halted 0 ms 0 KB -