답안 #1092232

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1092232 2024-09-23T15:47:40 Z TlenekWodoru 분수 공원 (IOI21_parks) C++17
55 / 100
994 ms 128212 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++)
    {
        match[i]=-1;
        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 Upgrade(int v)
{
    zaj[v]=1;
    Sprz.push_back(v);
    for(int som : D[v])
    {
        if(zaj[match[som]]==0)
        {
            Upgrade(match[som]);
            match[v]=som;
            match[som]=v;
            return;
        }
        else if(match[som]!=v)
        {
            break;
        }
    }
    for(int u : Sprz){zaj[u]=0;}
    Sprz.clear();
    match[v]=-1;
}
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++){g[i]=i;}
    SKOJ();
for(int I=1;I<=10;I++)
{
    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);
        }
    }
    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);
                Polacz(u,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;
    }
    for(int u : U)
    {
        if(match[u]!=-1){continue;}
        Upgrade(u);
    }
}
    return 0;
    if (X.size() == 1)
    {
        build({}, {}, {}, {});
        return 1;
    }
    vector<int> u, v, a, b;
    u.push_back(0);
    v.push_back(1);
    a.push_back(X[0]+1);
    b.push_back(Y[0]-1);
    build(u, v, a, b);
    return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 30044 KB Output is correct
2 Correct 8 ms 30044 KB Output is correct
3 Correct 8 ms 30036 KB Output is correct
4 Correct 8 ms 30040 KB Output is correct
5 Correct 8 ms 30248 KB Output is correct
6 Correct 9 ms 30044 KB Output is correct
7 Correct 9 ms 30044 KB Output is correct
8 Correct 9 ms 30044 KB Output is correct
9 Correct 285 ms 77280 KB Output is correct
10 Correct 25 ms 35160 KB Output is correct
11 Correct 115 ms 55808 KB Output is correct
12 Correct 34 ms 37460 KB Output is correct
13 Correct 40 ms 36184 KB Output is correct
14 Correct 9 ms 30300 KB Output is correct
15 Correct 10 ms 30300 KB Output is correct
16 Correct 309 ms 76216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 30044 KB Output is correct
2 Correct 8 ms 30044 KB Output is correct
3 Correct 8 ms 30036 KB Output is correct
4 Correct 8 ms 30040 KB Output is correct
5 Correct 8 ms 30248 KB Output is correct
6 Correct 9 ms 30044 KB Output is correct
7 Correct 9 ms 30044 KB Output is correct
8 Correct 9 ms 30044 KB Output is correct
9 Correct 285 ms 77280 KB Output is correct
10 Correct 25 ms 35160 KB Output is correct
11 Correct 115 ms 55808 KB Output is correct
12 Correct 34 ms 37460 KB Output is correct
13 Correct 40 ms 36184 KB Output is correct
14 Correct 9 ms 30300 KB Output is correct
15 Correct 10 ms 30300 KB Output is correct
16 Correct 309 ms 76216 KB Output is correct
17 Correct 9 ms 30040 KB Output is correct
18 Correct 9 ms 30044 KB Output is correct
19 Correct 10 ms 30080 KB Output is correct
20 Correct 9 ms 30044 KB Output is correct
21 Correct 9 ms 30044 KB Output is correct
22 Correct 10 ms 30040 KB Output is correct
23 Correct 985 ms 128212 KB Output is correct
24 Correct 9 ms 30044 KB Output is correct
25 Correct 11 ms 30852 KB Output is correct
26 Correct 12 ms 30556 KB Output is correct
27 Correct 11 ms 30812 KB Output is correct
28 Correct 301 ms 69108 KB Output is correct
29 Correct 486 ms 89244 KB Output is correct
30 Correct 753 ms 108876 KB Output is correct
31 Correct 994 ms 127716 KB Output is correct
32 Correct 10 ms 30044 KB Output is correct
33 Correct 9 ms 30044 KB Output is correct
34 Correct 8 ms 30040 KB Output is correct
35 Correct 9 ms 30044 KB Output is correct
36 Correct 9 ms 30228 KB Output is correct
37 Correct 9 ms 30040 KB Output is correct
38 Correct 9 ms 30044 KB Output is correct
39 Correct 9 ms 30064 KB Output is correct
40 Correct 10 ms 30044 KB Output is correct
41 Correct 9 ms 30224 KB Output is correct
42 Correct 10 ms 30040 KB Output is correct
43 Correct 11 ms 30300 KB Output is correct
44 Correct 13 ms 30556 KB Output is correct
45 Correct 290 ms 69880 KB Output is correct
46 Correct 446 ms 87976 KB Output is correct
47 Correct 453 ms 87608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 30044 KB Output is correct
2 Correct 8 ms 30044 KB Output is correct
3 Correct 8 ms 30036 KB Output is correct
4 Correct 8 ms 30040 KB Output is correct
5 Correct 8 ms 30248 KB Output is correct
6 Correct 9 ms 30044 KB Output is correct
7 Correct 9 ms 30044 KB Output is correct
8 Correct 9 ms 30044 KB Output is correct
9 Correct 285 ms 77280 KB Output is correct
10 Correct 25 ms 35160 KB Output is correct
11 Correct 115 ms 55808 KB Output is correct
12 Correct 34 ms 37460 KB Output is correct
13 Correct 40 ms 36184 KB Output is correct
14 Correct 9 ms 30300 KB Output is correct
15 Correct 10 ms 30300 KB Output is correct
16 Correct 309 ms 76216 KB Output is correct
17 Correct 9 ms 30040 KB Output is correct
18 Correct 9 ms 30044 KB Output is correct
19 Correct 10 ms 30080 KB Output is correct
20 Correct 9 ms 30044 KB Output is correct
21 Correct 9 ms 30044 KB Output is correct
22 Correct 10 ms 30040 KB Output is correct
23 Correct 985 ms 128212 KB Output is correct
24 Correct 9 ms 30044 KB Output is correct
25 Correct 11 ms 30852 KB Output is correct
26 Correct 12 ms 30556 KB Output is correct
27 Correct 11 ms 30812 KB Output is correct
28 Correct 301 ms 69108 KB Output is correct
29 Correct 486 ms 89244 KB Output is correct
30 Correct 753 ms 108876 KB Output is correct
31 Correct 994 ms 127716 KB Output is correct
32 Correct 10 ms 30044 KB Output is correct
33 Correct 9 ms 30044 KB Output is correct
34 Correct 8 ms 30040 KB Output is correct
35 Correct 9 ms 30044 KB Output is correct
36 Correct 9 ms 30228 KB Output is correct
37 Correct 9 ms 30040 KB Output is correct
38 Correct 9 ms 30044 KB Output is correct
39 Correct 9 ms 30064 KB Output is correct
40 Correct 10 ms 30044 KB Output is correct
41 Correct 9 ms 30224 KB Output is correct
42 Correct 10 ms 30040 KB Output is correct
43 Correct 11 ms 30300 KB Output is correct
44 Correct 13 ms 30556 KB Output is correct
45 Correct 290 ms 69880 KB Output is correct
46 Correct 446 ms 87976 KB Output is correct
47 Correct 453 ms 87608 KB Output is correct
48 Correct 9 ms 30044 KB Output is correct
49 Correct 9 ms 30044 KB Output is correct
50 Correct 9 ms 30252 KB Output is correct
51 Correct 11 ms 30044 KB Output is correct
52 Correct 9 ms 30040 KB Output is correct
53 Correct 9 ms 30040 KB Output is correct
54 Correct 10 ms 30056 KB Output is correct
55 Incorrect 981 ms 120056 KB Given structure is not connected: There is no path between vertices 0 and 3236
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 30044 KB Output is correct
2 Correct 8 ms 30044 KB Output is correct
3 Correct 8 ms 30036 KB Output is correct
4 Correct 8 ms 30040 KB Output is correct
5 Correct 8 ms 30248 KB Output is correct
6 Correct 9 ms 30044 KB Output is correct
7 Correct 9 ms 30044 KB Output is correct
8 Correct 9 ms 30044 KB Output is correct
9 Correct 285 ms 77280 KB Output is correct
10 Correct 25 ms 35160 KB Output is correct
11 Correct 115 ms 55808 KB Output is correct
12 Correct 34 ms 37460 KB Output is correct
13 Correct 40 ms 36184 KB Output is correct
14 Correct 9 ms 30300 KB Output is correct
15 Correct 10 ms 30300 KB Output is correct
16 Correct 309 ms 76216 KB Output is correct
17 Correct 10 ms 30044 KB Output is correct
18 Correct 9 ms 30044 KB Output is correct
19 Correct 9 ms 30040 KB Output is correct
20 Correct 673 ms 110152 KB Output is correct
21 Correct 725 ms 103488 KB Output is correct
22 Correct 653 ms 102980 KB Output is correct
23 Correct 582 ms 108968 KB Output is correct
24 Correct 173 ms 47192 KB Output is correct
25 Correct 284 ms 53844 KB Output is correct
26 Correct 265 ms 53692 KB Output is correct
27 Correct 739 ms 118440 KB Output is correct
28 Correct 731 ms 118444 KB Output is correct
29 Correct 685 ms 118444 KB Output is correct
30 Correct 714 ms 118468 KB Output is correct
31 Correct 12 ms 30040 KB Output is correct
32 Correct 39 ms 35980 KB Output is correct
33 Correct 78 ms 39272 KB Output is correct
34 Correct 705 ms 108620 KB Output is correct
35 Correct 16 ms 31320 KB Output is correct
36 Correct 60 ms 36432 KB Output is correct
37 Correct 126 ms 42832 KB Output is correct
38 Correct 224 ms 59320 KB Output is correct
39 Correct 308 ms 69884 KB Output is correct
40 Correct 458 ms 80556 KB Output is correct
41 Correct 561 ms 91560 KB Output is correct
42 Correct 678 ms 102308 KB Output is correct
43 Correct 9 ms 30044 KB Output is correct
44 Correct 9 ms 30180 KB Output is correct
45 Correct 9 ms 30208 KB Output is correct
46 Correct 8 ms 30044 KB Output is correct
47 Correct 9 ms 30040 KB Output is correct
48 Correct 10 ms 30140 KB Output is correct
49 Correct 8 ms 30044 KB Output is correct
50 Correct 10 ms 30044 KB Output is correct
51 Correct 9 ms 30044 KB Output is correct
52 Correct 9 ms 30040 KB Output is correct
53 Correct 9 ms 30044 KB Output is correct
54 Correct 10 ms 30444 KB Output is correct
55 Correct 11 ms 30552 KB Output is correct
56 Correct 296 ms 69816 KB Output is correct
57 Correct 434 ms 87980 KB Output is correct
58 Correct 444 ms 87720 KB Output is correct
59 Correct 9 ms 30044 KB Output is correct
60 Correct 9 ms 30040 KB Output is correct
61 Correct 9 ms 30200 KB Output is correct
62 Correct 663 ms 123052 KB Output is correct
63 Correct 657 ms 123144 KB Output is correct
64 Correct 679 ms 123312 KB Output is correct
65 Correct 12 ms 30556 KB Output is correct
66 Correct 16 ms 31144 KB Output is correct
67 Correct 302 ms 68436 KB Output is correct
68 Correct 479 ms 88228 KB Output is correct
69 Correct 669 ms 106520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 30044 KB Output is correct
2 Correct 8 ms 30044 KB Output is correct
3 Correct 8 ms 30036 KB Output is correct
4 Correct 8 ms 30040 KB Output is correct
5 Correct 8 ms 30248 KB Output is correct
6 Correct 9 ms 30044 KB Output is correct
7 Correct 9 ms 30044 KB Output is correct
8 Correct 9 ms 30044 KB Output is correct
9 Correct 285 ms 77280 KB Output is correct
10 Correct 25 ms 35160 KB Output is correct
11 Correct 115 ms 55808 KB Output is correct
12 Correct 34 ms 37460 KB Output is correct
13 Correct 40 ms 36184 KB Output is correct
14 Correct 9 ms 30300 KB Output is correct
15 Correct 10 ms 30300 KB Output is correct
16 Correct 309 ms 76216 KB Output is correct
17 Correct 777 ms 125152 KB Output is correct
18 Correct 721 ms 124584 KB Output is correct
19 Correct 711 ms 103488 KB Output is correct
20 Correct 772 ms 111792 KB Output is correct
21 Correct 666 ms 107084 KB Output is correct
22 Correct 13 ms 30044 KB Output is correct
23 Correct 91 ms 42444 KB Output is correct
24 Correct 29 ms 32760 KB Output is correct
25 Correct 92 ms 39500 KB Output is correct
26 Correct 167 ms 46156 KB Output is correct
27 Correct 356 ms 70612 KB Output is correct
28 Correct 426 ms 81004 KB Output is correct
29 Correct 535 ms 90916 KB Output is correct
30 Correct 667 ms 100876 KB Output is correct
31 Correct 816 ms 111016 KB Output is correct
32 Correct 780 ms 118348 KB Output is correct
33 Correct 703 ms 124688 KB Output is correct
34 Correct 13 ms 30808 KB Output is correct
35 Correct 16 ms 31324 KB Output is correct
36 Correct 305 ms 70996 KB Output is correct
37 Correct 486 ms 92072 KB Output is correct
38 Correct 691 ms 111532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 30044 KB Output is correct
2 Correct 8 ms 30044 KB Output is correct
3 Correct 8 ms 30036 KB Output is correct
4 Correct 8 ms 30040 KB Output is correct
5 Correct 8 ms 30248 KB Output is correct
6 Correct 9 ms 30044 KB Output is correct
7 Correct 9 ms 30044 KB Output is correct
8 Correct 9 ms 30044 KB Output is correct
9 Correct 285 ms 77280 KB Output is correct
10 Correct 25 ms 35160 KB Output is correct
11 Correct 115 ms 55808 KB Output is correct
12 Correct 34 ms 37460 KB Output is correct
13 Correct 40 ms 36184 KB Output is correct
14 Correct 9 ms 30300 KB Output is correct
15 Correct 10 ms 30300 KB Output is correct
16 Correct 309 ms 76216 KB Output is correct
17 Correct 9 ms 30040 KB Output is correct
18 Correct 9 ms 30044 KB Output is correct
19 Correct 10 ms 30080 KB Output is correct
20 Correct 9 ms 30044 KB Output is correct
21 Correct 9 ms 30044 KB Output is correct
22 Correct 10 ms 30040 KB Output is correct
23 Correct 985 ms 128212 KB Output is correct
24 Correct 9 ms 30044 KB Output is correct
25 Correct 11 ms 30852 KB Output is correct
26 Correct 12 ms 30556 KB Output is correct
27 Correct 11 ms 30812 KB Output is correct
28 Correct 301 ms 69108 KB Output is correct
29 Correct 486 ms 89244 KB Output is correct
30 Correct 753 ms 108876 KB Output is correct
31 Correct 994 ms 127716 KB Output is correct
32 Correct 10 ms 30044 KB Output is correct
33 Correct 9 ms 30044 KB Output is correct
34 Correct 8 ms 30040 KB Output is correct
35 Correct 9 ms 30044 KB Output is correct
36 Correct 9 ms 30228 KB Output is correct
37 Correct 9 ms 30040 KB Output is correct
38 Correct 9 ms 30044 KB Output is correct
39 Correct 9 ms 30064 KB Output is correct
40 Correct 10 ms 30044 KB Output is correct
41 Correct 9 ms 30224 KB Output is correct
42 Correct 10 ms 30040 KB Output is correct
43 Correct 11 ms 30300 KB Output is correct
44 Correct 13 ms 30556 KB Output is correct
45 Correct 290 ms 69880 KB Output is correct
46 Correct 446 ms 87976 KB Output is correct
47 Correct 453 ms 87608 KB Output is correct
48 Correct 9 ms 30044 KB Output is correct
49 Correct 9 ms 30044 KB Output is correct
50 Correct 9 ms 30252 KB Output is correct
51 Correct 11 ms 30044 KB Output is correct
52 Correct 9 ms 30040 KB Output is correct
53 Correct 9 ms 30040 KB Output is correct
54 Correct 10 ms 30056 KB Output is correct
55 Incorrect 981 ms 120056 KB Given structure is not connected: There is no path between vertices 0 and 3236
56 Halted 0 ms 0 KB -