Submission #824747

# Submission time Handle Problem Language Result Execution time Memory
824747 2023-08-14T09:24:48 Z andrei_boaca Fountain Parks (IOI21_parks) C++17
15 / 100
334 ms 52132 KB
#include "parks.h"
#include <bits/stdc++.h>
//#include "grader.cpp"
using namespace std;

typedef pair<int,int> pii;
map<pii,int> ind;
map<pii,int> ocup;
map<pii,int> match;
struct point
{
    int x,y;
} v[200005];
int k;
vector<int> myy[200005];
vector<int> muchii[200005];
bool have[11][200005];
bool use[200005];
void dfs(int nod)
{
    use[nod]=1;
    for(int i:muchii[nod])
        if(!use[i])
            dfs(i);
}
int c[11][200005];
vector<int> U,V,A,B;
void addedge(int xa,int ya,int xb,int yb,int xc,int yc)
{
    int a=ind[{xa,ya}];
    int b=ind[{xb,yb}];
    U.push_back(a);
    V.push_back(b);
    A.push_back(xc);
    B.push_back(yc);
}
int construct_roads(std::vector<int> X, std::vector<int> Y)
{
    k=X.size();
    int xmax=0;
    for(int i=0;i<k;i++)
    {
        v[i]={X[i],Y[i]};
        ind[{X[i],Y[i]}]=i;
        xmax=max(xmax,X[i]);
        myy[X[i]].push_back(Y[i]);
        have[X[i]][Y[i]]=1;
    }
    if(xmax<=2)
    {
        sort(myy[2].begin(),myy[2].end());
        vector<int> U,V,a,b;
        for(int i=1;i<myy[2].size();i++)
        {
            if(myy[2][i]-myy[2][i-1]!=2)
                return 0;
            int x=2;
            int yu=myy[2][i-1];
            int yv=myy[2][i];
            U.push_back(ind[{x,yu}]);
            V.push_back(ind[{x,yv}]);
            a.push_back(x-1);
            b.push_back(yv-1);
        }
        build(U,V,a,b);
        return 1;
    }
    if(xmax<=4)
    {
        sort(myy[2].begin(),myy[2].end());
        sort(myy[4].begin(),myy[4].end());
        vector<int> U,V,A,B;
        for(int i=2;i<=200000;i+=2)
            if(have[2][i]&&have[2][i-2])
            {
                int a=ind[{2,i}];
                int b=ind[{2,i-2}];
                U.push_back(a);
                V.push_back(b);
                muchii[a].push_back(b);
                muchii[b].push_back(a);
                A.push_back(1);
                B.push_back(i-1);
            }
        for(int i=2;i<=200000;i+=2)
            if(have[4][i]&&have[4][i-2])
            {
                int a=ind[{4,i}];
                int b=ind[{4,i-2}];
                U.push_back(a);
                V.push_back(b);
                muchii[a].push_back(b);
                muchii[b].push_back(a);
                A.push_back(5);
                B.push_back(i-1);
            }
        for(int i=2;i<=200000;i+=2)
            if(have[2][i]&&have[4][i])
            {
                int a=ind[{2,i}];
                int b=ind[{4,i}];
                U.push_back(a);
                V.push_back(b);
                muchii[a].push_back(b);
                muchii[b].push_back(a);
                A.push_back(3);
                B.push_back(i+1);
            }
        dfs(0);
        for(int i=0;i<k;i++)
            if(!use[i])
                return 0;
        build(U,V,A,B);
        return 1;
    }
    if(xmax<=6)
    {
        sort(myy[2].begin(),myy[2].end());
        sort(myy[4].begin(),myy[4].end());
        sort(myy[6].begin(),myy[6].end());
        int nr=0;
        for(int i=2;i<=200000;i+=2)
            if(have[2][i])
            {
                if(have[2][i-2])
                {
                    addedge(2,i,2,i-2,1,i-1);
                    c[2][i]=c[2][i-2];
                }
                else
                {
                    nr++;
                    c[2][i]=nr;
                }
            }
        for(int i=2;i<=200000;i+=2)
            if(have[6][i])
            {
                if(have[6][i-2])
                {
                    addedge(6,i,6,i-2,7,i-1);
                    c[6][i]=c[6][i-2];
                }
                else
                {
                    nr++;
                    c[6][i]=nr;
                }
            }
        int lft=1;
        for(int i=2;i<=200000;i+=2)
            if(have[4][i])
            {
                if(have[4][i-2])
                {
                    if(lft==1)
                    {
                        addedge(4,i,4,i-2,3,i-1);
                        ocup[{3,i-1}]=1;
                    }
                    else
                    {
                        addedge(4,i,4,i-2,5,i-1);
                        ocup[{5,i-1}]=1;
                    }
                    lft^=1;
                    c[4][i]=c[4][i-2];
                }
                else
                {
                    lft=1;
                    nr++;
                    c[4][i]=nr;
                }
            }
        for(int i=2;i<=200000;i+=2)
            if(have[2][i]&&have[4][i])
            {
                int a=c[2][i];
                int b=c[4][i];
                if(match[{a,b}]==0)
                    {
                        match[{a,b}]=1;
                        if(!ocup[{3,i-1}])
                            {
                                addedge(2,i,4,i,3,i-1);
                                ocup[{3,i-1}]=1;
                            }
                        else
                        {
                            addedge(2,i,4,i,3,i+1);
                            ocup[{3,i+1}]=1;
                        }
                    }
            }
        for(int i=2;i<=200000;i+=2)
            if(have[4][i]&&have[6][i])
            {
                int a=c[4][i];
                int b=c[6][i];
                if(match[{a,b}]==0)
                    {
                        match[{a,b}]=1;
                        if(!ocup[{5,i-1}])
                            {
                                addedge(2,i,4,i,5,i-1);
                                ocup[{5,i-1}]=1;
                            }
                        else
                        {
                            addedge(2,i,4,i,5,i+1);
                            ocup[{5,i+1}]=1;
                        }
                    }
            }
        dfs(0);
        for(int i=0;i<k;i++)
            if(!use[i])
                return 0;
        build(U,V,A,B);
        return 1;
    }
}

Compilation message

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:53:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         for(int i=1;i<myy[2].size();i++)
      |                     ~^~~~~~~~~~~~~~
parks.cpp:223:1: warning: control reaches end of non-void function [-Wreturn-type]
  223 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9684 KB Output is correct
2 Correct 4 ms 9644 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9620 KB Output is correct
5 Correct 4 ms 9684 KB Output is correct
6 Correct 4 ms 9684 KB Output is correct
7 Correct 4 ms 9684 KB Output is correct
8 Correct 7 ms 9684 KB Output is correct
9 Correct 96 ms 23968 KB Output is correct
10 Correct 11 ms 11348 KB Output is correct
11 Correct 48 ms 17432 KB Output is correct
12 Correct 14 ms 12024 KB Output is correct
13 Correct 22 ms 14544 KB Output is correct
14 Correct 5 ms 9736 KB Output is correct
15 Correct 5 ms 9812 KB Output is correct
16 Correct 102 ms 23896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9684 KB Output is correct
2 Correct 4 ms 9644 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9620 KB Output is correct
5 Correct 4 ms 9684 KB Output is correct
6 Correct 4 ms 9684 KB Output is correct
7 Correct 4 ms 9684 KB Output is correct
8 Correct 7 ms 9684 KB Output is correct
9 Correct 96 ms 23968 KB Output is correct
10 Correct 11 ms 11348 KB Output is correct
11 Correct 48 ms 17432 KB Output is correct
12 Correct 14 ms 12024 KB Output is correct
13 Correct 22 ms 14544 KB Output is correct
14 Correct 5 ms 9736 KB Output is correct
15 Correct 5 ms 9812 KB Output is correct
16 Correct 102 ms 23896 KB Output is correct
17 Correct 5 ms 9684 KB Output is correct
18 Correct 4 ms 9684 KB Output is correct
19 Correct 4 ms 9684 KB Output is correct
20 Correct 4 ms 9684 KB Output is correct
21 Correct 4 ms 9684 KB Output is correct
22 Correct 4 ms 9684 KB Output is correct
23 Correct 334 ms 52056 KB Output is correct
24 Correct 4 ms 9684 KB Output is correct
25 Correct 6 ms 9940 KB Output is correct
26 Correct 6 ms 10196 KB Output is correct
27 Correct 7 ms 10324 KB Output is correct
28 Correct 113 ms 26668 KB Output is correct
29 Correct 177 ms 35184 KB Output is correct
30 Correct 253 ms 43580 KB Output is correct
31 Correct 312 ms 52132 KB Output is correct
32 Correct 4 ms 9684 KB Output is correct
33 Correct 5 ms 9684 KB Output is correct
34 Correct 4 ms 9684 KB Output is correct
35 Correct 5 ms 9684 KB Output is correct
36 Correct 4 ms 9684 KB Output is correct
37 Correct 4 ms 9684 KB Output is correct
38 Correct 4 ms 9720 KB Output is correct
39 Correct 4 ms 9684 KB Output is correct
40 Correct 4 ms 9684 KB Output is correct
41 Correct 4 ms 9684 KB Output is correct
42 Correct 4 ms 9684 KB Output is correct
43 Correct 6 ms 9940 KB Output is correct
44 Correct 6 ms 10196 KB Output is correct
45 Correct 112 ms 27948 KB Output is correct
46 Correct 213 ms 36552 KB Output is correct
47 Correct 213 ms 36436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9684 KB Output is correct
2 Correct 4 ms 9644 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9620 KB Output is correct
5 Correct 4 ms 9684 KB Output is correct
6 Correct 4 ms 9684 KB Output is correct
7 Correct 4 ms 9684 KB Output is correct
8 Correct 7 ms 9684 KB Output is correct
9 Correct 96 ms 23968 KB Output is correct
10 Correct 11 ms 11348 KB Output is correct
11 Correct 48 ms 17432 KB Output is correct
12 Correct 14 ms 12024 KB Output is correct
13 Correct 22 ms 14544 KB Output is correct
14 Correct 5 ms 9736 KB Output is correct
15 Correct 5 ms 9812 KB Output is correct
16 Correct 102 ms 23896 KB Output is correct
17 Correct 5 ms 9684 KB Output is correct
18 Correct 4 ms 9684 KB Output is correct
19 Correct 4 ms 9684 KB Output is correct
20 Correct 4 ms 9684 KB Output is correct
21 Correct 4 ms 9684 KB Output is correct
22 Correct 4 ms 9684 KB Output is correct
23 Correct 334 ms 52056 KB Output is correct
24 Correct 4 ms 9684 KB Output is correct
25 Correct 6 ms 9940 KB Output is correct
26 Correct 6 ms 10196 KB Output is correct
27 Correct 7 ms 10324 KB Output is correct
28 Correct 113 ms 26668 KB Output is correct
29 Correct 177 ms 35184 KB Output is correct
30 Correct 253 ms 43580 KB Output is correct
31 Correct 312 ms 52132 KB Output is correct
32 Correct 4 ms 9684 KB Output is correct
33 Correct 5 ms 9684 KB Output is correct
34 Correct 4 ms 9684 KB Output is correct
35 Correct 5 ms 9684 KB Output is correct
36 Correct 4 ms 9684 KB Output is correct
37 Correct 4 ms 9684 KB Output is correct
38 Correct 4 ms 9720 KB Output is correct
39 Correct 4 ms 9684 KB Output is correct
40 Correct 4 ms 9684 KB Output is correct
41 Correct 4 ms 9684 KB Output is correct
42 Correct 4 ms 9684 KB Output is correct
43 Correct 6 ms 9940 KB Output is correct
44 Correct 6 ms 10196 KB Output is correct
45 Correct 112 ms 27948 KB Output is correct
46 Correct 213 ms 36552 KB Output is correct
47 Correct 213 ms 36436 KB Output is correct
48 Incorrect 5 ms 9684 KB Solution announced impossible, but it is possible.
49 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9684 KB Output is correct
2 Correct 4 ms 9644 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9620 KB Output is correct
5 Correct 4 ms 9684 KB Output is correct
6 Correct 4 ms 9684 KB Output is correct
7 Correct 4 ms 9684 KB Output is correct
8 Correct 7 ms 9684 KB Output is correct
9 Correct 96 ms 23968 KB Output is correct
10 Correct 11 ms 11348 KB Output is correct
11 Correct 48 ms 17432 KB Output is correct
12 Correct 14 ms 12024 KB Output is correct
13 Correct 22 ms 14544 KB Output is correct
14 Correct 5 ms 9736 KB Output is correct
15 Correct 5 ms 9812 KB Output is correct
16 Correct 102 ms 23896 KB Output is correct
17 Runtime error 12 ms 19412 KB Execution killed with signal 11
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9684 KB Output is correct
2 Correct 4 ms 9644 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9620 KB Output is correct
5 Correct 4 ms 9684 KB Output is correct
6 Correct 4 ms 9684 KB Output is correct
7 Correct 4 ms 9684 KB Output is correct
8 Correct 7 ms 9684 KB Output is correct
9 Correct 96 ms 23968 KB Output is correct
10 Correct 11 ms 11348 KB Output is correct
11 Correct 48 ms 17432 KB Output is correct
12 Correct 14 ms 12024 KB Output is correct
13 Correct 22 ms 14544 KB Output is correct
14 Correct 5 ms 9736 KB Output is correct
15 Correct 5 ms 9812 KB Output is correct
16 Correct 102 ms 23896 KB Output is correct
17 Runtime error 43 ms 25744 KB Execution killed with signal 11
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9684 KB Output is correct
2 Correct 4 ms 9644 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9620 KB Output is correct
5 Correct 4 ms 9684 KB Output is correct
6 Correct 4 ms 9684 KB Output is correct
7 Correct 4 ms 9684 KB Output is correct
8 Correct 7 ms 9684 KB Output is correct
9 Correct 96 ms 23968 KB Output is correct
10 Correct 11 ms 11348 KB Output is correct
11 Correct 48 ms 17432 KB Output is correct
12 Correct 14 ms 12024 KB Output is correct
13 Correct 22 ms 14544 KB Output is correct
14 Correct 5 ms 9736 KB Output is correct
15 Correct 5 ms 9812 KB Output is correct
16 Correct 102 ms 23896 KB Output is correct
17 Correct 5 ms 9684 KB Output is correct
18 Correct 4 ms 9684 KB Output is correct
19 Correct 4 ms 9684 KB Output is correct
20 Correct 4 ms 9684 KB Output is correct
21 Correct 4 ms 9684 KB Output is correct
22 Correct 4 ms 9684 KB Output is correct
23 Correct 334 ms 52056 KB Output is correct
24 Correct 4 ms 9684 KB Output is correct
25 Correct 6 ms 9940 KB Output is correct
26 Correct 6 ms 10196 KB Output is correct
27 Correct 7 ms 10324 KB Output is correct
28 Correct 113 ms 26668 KB Output is correct
29 Correct 177 ms 35184 KB Output is correct
30 Correct 253 ms 43580 KB Output is correct
31 Correct 312 ms 52132 KB Output is correct
32 Correct 4 ms 9684 KB Output is correct
33 Correct 5 ms 9684 KB Output is correct
34 Correct 4 ms 9684 KB Output is correct
35 Correct 5 ms 9684 KB Output is correct
36 Correct 4 ms 9684 KB Output is correct
37 Correct 4 ms 9684 KB Output is correct
38 Correct 4 ms 9720 KB Output is correct
39 Correct 4 ms 9684 KB Output is correct
40 Correct 4 ms 9684 KB Output is correct
41 Correct 4 ms 9684 KB Output is correct
42 Correct 4 ms 9684 KB Output is correct
43 Correct 6 ms 9940 KB Output is correct
44 Correct 6 ms 10196 KB Output is correct
45 Correct 112 ms 27948 KB Output is correct
46 Correct 213 ms 36552 KB Output is correct
47 Correct 213 ms 36436 KB Output is correct
48 Incorrect 5 ms 9684 KB Solution announced impossible, but it is possible.
49 Halted 0 ms 0 KB -