Submission #441456

# Submission time Handle Problem Language Result Execution time Memory
441456 2021-07-05T08:21:29 Z daniel920712 Fountain Parks (IOI21_parks) C++17
55 / 100
2005 ms 84608 KB
#include "parks.h"
#include <map>
#include <utility>
#include <queue>
#include <set>
using namespace std;
map < pair < int , int > , int > all,con;
map < pair < int , int > , pair < int , int > > road;
vector < int > u,v,a,b;
queue < pair < int , int > > BFS;
set < pair < int , int > > still,Not,have;
int Father[200005];
int Find(int here)
{
    if(Father[here]==here) return here;
    Father[here]=Find(Father[here]);
    return Father[here];
}
int construct_roads(vector < int > x, vector < int > y)
{
    int N=x.size(),M,i,t,aa,bb,ok=1,xx,yy,big;
    for(i=0;i<N;i++)
    {
        all[make_pair(x[i],y[i])]=i;
        Father[i]=i;
        big=max(big,x[i]);
    }
    if(big<=6)
    {
        for(i=0;i<N;i++)
        {
            if(all.find(make_pair(x[i],y[i]+2))!=all.end())
            {
                t=all[make_pair(x[i],y[i]+2)];
                aa=Find(i);
                bb=Find(t);
                if(aa!=bb) Father[aa]=bb;
                if(x[i]==2)
                {
                    u.push_back(i);
                    v.push_back(t);
                    a.push_back(x[i]-1);
                    b.push_back(y[i]+1);
                }
                else if(x[i]==4)
                {
                    if(y[i]%4==0)
                    {
                        u.push_back(i);
                        v.push_back(t);
                        a.push_back(x[i]-1);
                        b.push_back(y[i]+1);
                    }
                    else
                    {
                        u.push_back(i);
                        v.push_back(t);
                        a.push_back(x[i]+1);
                        b.push_back(y[i]+1);
                    }
                }
                else if(x[i]==6)
                {
                    u.push_back(i);
                    v.push_back(t);
                    a.push_back(x[i]+1);
                    b.push_back(y[i]+1);
                }

            }
            if(all.find(make_pair(x[i]+2,y[i]))!=all.end())
            {
                t=all[make_pair(x[i]+2,y[i])];
                aa=Find(i);
                bb=Find(t);
                if(aa!=bb) Father[aa]=bb;
                if(y[i]%4==0)
                {
                    if(x[i]==2)
                    {
                        u.push_back(i);
                        v.push_back(t);
                        a.push_back(x[i]+1);
                        b.push_back(y[i]-1);
                    }
                    else
                    {
                        u.push_back(i);
                        v.push_back(t);
                        a.push_back(x[i]+1);
                        b.push_back(y[i]+1);
                    }
                }
                else
                {
                    Not.insert(make_pair(i,t));
                }
            }
        }
        M=a.size();
        for(i=0;i<M;i++) have.insert(make_pair(a[i],b[i]));
        for(auto i:Not)
        {
            if(have.find(make_pair(x[i.first]+1,y[i.first]+1))==have.end())
            {
                have.insert(make_pair(x[i.first]+1,y[i.first]+1));
                u.push_back(i.first);
                v.push_back(i.second);
                a.push_back(x[i.first]+1);
                b.push_back(y[i.first]+1);
            }
            else if(have.find(make_pair(x[i.first]+1,y[i.first]-1))==have.end())
            {
                have.insert(make_pair(x[i.first]+1,y[i.first]-1));
                u.push_back(i.first);
                v.push_back(i.second);
                a.push_back(x[i.first]+1);
                b.push_back(y[i.first]-1);
            }
        }
        t=Find(0);
        for(i=0;i<N;i++)
        {
            //printf("%d %d\n",t,Find(i));
            if(t!=Find(i)) ok=0;
        }
        if(ok==0) return ok;



        if(ok) build(u,v,a,b);
        return ok;
    }
    else
    {
        for(i=0;i<N;i++)
        {
            if(all.find(make_pair(x[i],y[i]+2))!=all.end())
            {
                t=all[make_pair(x[i],y[i]+2)];
                road[make_pair(x[i],y[i]+1)]=make_pair(i,t);
                con[make_pair(x[i]+1,y[i]+1)]++;
                con[make_pair(x[i]-1,y[i]+1)]++;

                aa=Find(i);
                bb=Find(t);
                if(aa!=bb) Father[aa]=bb;

            }
            if(all.find(make_pair(x[i]+2,y[i]))!=all.end())
            {
                t=all[make_pair(x[i]+2,y[i])];
                road[make_pair(x[i]+1,y[i])]=make_pair(i,t);
                con[make_pair(x[i]+1,y[i]+1)]++;
                con[make_pair(x[i]+1,y[i]-1)]++;
                aa=Find(i);
                bb=Find(t);
                if(aa!=bb) Father[aa]=bb;
            }
        }
        t=Find(0);
        for(i=0;i<N;i++)  if(t!=Find(i)) ok=0;
        if(ok==0) return ok;
        for(auto i:con)
        {
            still.insert(i.first);
            if(i.second==1) BFS.push(i.first);
        }
        while(!BFS.empty())
        {
            xx=BFS.front().first;
            yy=BFS.front().second;
            BFS.pop();
            still.erase(make_pair(xx,yy));
            if(con[make_pair(xx,yy)]<=0) continue;
            if(road.find(make_pair(xx+1,yy))!=road.end()) aa=xx+1,bb=yy;
            if(road.find(make_pair(xx-1,yy))!=road.end()) aa=xx-1,bb=yy;
            if(road.find(make_pair(xx,yy+1))!=road.end()) aa=xx,bb=yy+1;
            if(road.find(make_pair(xx,yy-1))!=road.end()) aa=xx,bb=yy-1;
            u.push_back(road[make_pair(aa,bb)].first);
            v.push_back(road[make_pair(aa,bb)].second);
            a.push_back(xx);
            b.push_back(yy);
            road.erase(make_pair(aa,bb));
            con[make_pair(xx,yy)]=0;

            if(aa%2==0)
            {
                con[make_pair(aa-1,bb)]--;
                con[make_pair(aa+1,bb)]--;

                if(con[make_pair(aa-1,bb)]==1) BFS.push(make_pair(aa-1,bb));
                if(con[make_pair(aa+1,bb)]==1) BFS.push(make_pair(aa+1,bb));
            }
            else
            {
                con[make_pair(aa,bb-1)]--;
                con[make_pair(aa,bb+1)]--;

                if(con[make_pair(aa,bb-1)]==1) BFS.push(make_pair(aa,bb-1));
                if(con[make_pair(aa,bb+1)]==1) BFS.push(make_pair(aa,bb+1));
            }

        }
        while(!still.empty())
        {
            BFS.push(*still.begin());
            while(!BFS.empty())
            {
                ok=0;
                xx=BFS.front().first;
                yy=BFS.front().second;
                BFS.pop();
                still.erase(make_pair(xx,yy));
                if(con[make_pair(xx,yy)]<=0) continue;
                if(road.find(make_pair(xx+1,yy))!=road.end()) aa=xx+1,bb=yy,ok=1;
                if(road.find(make_pair(xx-1,yy))!=road.end()) aa=xx-1,bb=yy,ok=1;
                if(road.find(make_pair(xx,yy+1))!=road.end()) aa=xx,bb=yy+1,ok=1;
                if(road.find(make_pair(xx,yy-1))!=road.end()) aa=xx,bb=yy-1,ok=1;
                con[make_pair(xx,yy)]=0;

                if(ok==0) continue;
                u.push_back(road[make_pair(aa,bb)].first);
                v.push_back(road[make_pair(aa,bb)].second);
                a.push_back(xx);
                b.push_back(yy);
                road.erase(make_pair(aa,bb));

                if(aa%2==0)
                {
                    con[make_pair(aa-1,bb)]--;
                    con[make_pair(aa+1,bb)]--;

                    if(con[make_pair(aa-1,bb)]==1) BFS.push(make_pair(aa-1,bb));
                    if(con[make_pair(aa+1,bb)]==1) BFS.push(make_pair(aa+1,bb));
                }
                else
                {
                    con[make_pair(aa,bb-1)]--;
                    con[make_pair(aa,bb+1)]--;

                    if(con[make_pair(aa,bb-1)]==1) BFS.push(make_pair(aa,bb-1));
                    if(con[make_pair(aa,bb+1)]==1) BFS.push(make_pair(aa,bb+1));
                }

            }
        }
        if(!road.empty()) return 0;


        if(ok) build(u,v,a,b);
        return ok;
    }

}

Compilation message

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:28:5: warning: 'big' may be used uninitialized in this function [-Wmaybe-uninitialized]
   28 |     if(big<=6)
      |     ^~
parks.cpp:193:74: warning: 'bb' may be used uninitialized in this function [-Wmaybe-uninitialized]
  193 |                 if(con[make_pair(aa+1,bb)]==1) BFS.push(make_pair(aa+1,bb));
      |                                                                          ^
parks.cpp:197:38: warning: 'aa' may be used uninitialized in this function [-Wmaybe-uninitialized]
  197 |                 con[make_pair(aa,bb-1)]--;
      |                                      ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 215 ms 17844 KB Output is correct
10 Correct 14 ms 2284 KB Output is correct
11 Correct 220 ms 22084 KB Output is correct
12 Correct 51 ms 6380 KB Output is correct
13 Correct 45 ms 7080 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 4 ms 716 KB Output is correct
16 Correct 535 ms 39968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 215 ms 17844 KB Output is correct
10 Correct 14 ms 2284 KB Output is correct
11 Correct 220 ms 22084 KB Output is correct
12 Correct 51 ms 6380 KB Output is correct
13 Correct 45 ms 7080 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 4 ms 716 KB Output is correct
16 Correct 535 ms 39968 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 734 ms 42572 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 4 ms 716 KB Output is correct
26 Correct 4 ms 716 KB Output is correct
27 Correct 6 ms 920 KB Output is correct
28 Correct 565 ms 30336 KB Output is correct
29 Correct 901 ms 49240 KB Output is correct
30 Correct 1208 ms 66456 KB Output is correct
31 Correct 1682 ms 81888 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 0 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 0 ms 204 KB Output is correct
37 Correct 0 ms 204 KB Output is correct
38 Correct 0 ms 204 KB Output is correct
39 Correct 0 ms 204 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
41 Correct 0 ms 204 KB Output is correct
42 Correct 0 ms 204 KB Output is correct
43 Correct 3 ms 716 KB Output is correct
44 Correct 4 ms 716 KB Output is correct
45 Correct 579 ms 33368 KB Output is correct
46 Correct 923 ms 48584 KB Output is correct
47 Correct 412 ms 26860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 215 ms 17844 KB Output is correct
10 Correct 14 ms 2284 KB Output is correct
11 Correct 220 ms 22084 KB Output is correct
12 Correct 51 ms 6380 KB Output is correct
13 Correct 45 ms 7080 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 4 ms 716 KB Output is correct
16 Correct 535 ms 39968 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 734 ms 42572 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 4 ms 716 KB Output is correct
26 Correct 4 ms 716 KB Output is correct
27 Correct 6 ms 920 KB Output is correct
28 Correct 565 ms 30336 KB Output is correct
29 Correct 901 ms 49240 KB Output is correct
30 Correct 1208 ms 66456 KB Output is correct
31 Correct 1682 ms 81888 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 0 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 0 ms 204 KB Output is correct
37 Correct 0 ms 204 KB Output is correct
38 Correct 0 ms 204 KB Output is correct
39 Correct 0 ms 204 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
41 Correct 0 ms 204 KB Output is correct
42 Correct 0 ms 204 KB Output is correct
43 Correct 3 ms 716 KB Output is correct
44 Correct 4 ms 716 KB Output is correct
45 Correct 579 ms 33368 KB Output is correct
46 Correct 923 ms 48584 KB Output is correct
47 Correct 412 ms 26860 KB Output is correct
48 Correct 0 ms 204 KB Output is correct
49 Correct 0 ms 204 KB Output is correct
50 Correct 0 ms 204 KB Output is correct
51 Correct 0 ms 204 KB Output is correct
52 Correct 0 ms 204 KB Output is correct
53 Correct 0 ms 204 KB Output is correct
54 Correct 0 ms 204 KB Output is correct
55 Incorrect 1554 ms 71980 KB Solution announced impossible, but it is possible.
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 215 ms 17844 KB Output is correct
10 Correct 14 ms 2284 KB Output is correct
11 Correct 220 ms 22084 KB Output is correct
12 Correct 51 ms 6380 KB Output is correct
13 Correct 45 ms 7080 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 4 ms 716 KB Output is correct
16 Correct 535 ms 39968 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1090 ms 58888 KB Output is correct
21 Correct 1261 ms 57680 KB Output is correct
22 Correct 1200 ms 58440 KB Output is correct
23 Correct 1045 ms 68816 KB Output is correct
24 Correct 332 ms 16824 KB Output is correct
25 Correct 957 ms 54204 KB Output is correct
26 Correct 869 ms 54212 KB Output is correct
27 Correct 1321 ms 83004 KB Output is correct
28 Correct 1331 ms 82988 KB Output is correct
29 Correct 1383 ms 82872 KB Output is correct
30 Correct 1380 ms 83640 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 64 ms 4968 KB Output is correct
33 Correct 131 ms 8364 KB Output is correct
34 Correct 1191 ms 57932 KB Output is correct
35 Correct 20 ms 2428 KB Output is correct
36 Correct 148 ms 11216 KB Output is correct
37 Correct 449 ms 22196 KB Output is correct
38 Correct 594 ms 25344 KB Output is correct
39 Correct 790 ms 34704 KB Output is correct
40 Correct 1027 ms 43728 KB Output is correct
41 Correct 1342 ms 53692 KB Output is correct
42 Correct 1649 ms 64296 KB Output is correct
43 Correct 0 ms 204 KB Output is correct
44 Correct 0 ms 204 KB Output is correct
45 Correct 0 ms 204 KB Output is correct
46 Correct 0 ms 204 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 0 ms 204 KB Output is correct
49 Correct 0 ms 204 KB Output is correct
50 Correct 0 ms 204 KB Output is correct
51 Correct 0 ms 204 KB Output is correct
52 Correct 1 ms 204 KB Output is correct
53 Correct 0 ms 204 KB Output is correct
54 Correct 2 ms 588 KB Output is correct
55 Correct 5 ms 972 KB Output is correct
56 Correct 229 ms 18600 KB Output is correct
57 Correct 928 ms 48480 KB Output is correct
58 Correct 934 ms 48520 KB Output is correct
59 Correct 0 ms 204 KB Output is correct
60 Correct 1 ms 204 KB Output is correct
61 Correct 0 ms 204 KB Output is correct
62 Correct 1205 ms 84608 KB Output is correct
63 Correct 518 ms 35484 KB Output is correct
64 Correct 543 ms 35480 KB Output is correct
65 Correct 5 ms 844 KB Output is correct
66 Correct 10 ms 1524 KB Output is correct
67 Correct 629 ms 32888 KB Output is correct
68 Correct 392 ms 27928 KB Output is correct
69 Correct 1452 ms 69008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 215 ms 17844 KB Output is correct
10 Correct 14 ms 2284 KB Output is correct
11 Correct 220 ms 22084 KB Output is correct
12 Correct 51 ms 6380 KB Output is correct
13 Correct 45 ms 7080 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 4 ms 716 KB Output is correct
16 Correct 535 ms 39968 KB Output is correct
17 Correct 1241 ms 82564 KB Output is correct
18 Correct 1265 ms 82044 KB Output is correct
19 Correct 1243 ms 60204 KB Output is correct
20 Correct 1661 ms 71832 KB Output is correct
21 Correct 1385 ms 70456 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 179 ms 10752 KB Output is correct
24 Correct 53 ms 5060 KB Output is correct
25 Correct 344 ms 16840 KB Output is correct
26 Correct 728 ms 28752 KB Output is correct
27 Correct 845 ms 34736 KB Output is correct
28 Correct 1135 ms 43788 KB Output is correct
29 Correct 1626 ms 52804 KB Output is correct
30 Correct 1645 ms 61388 KB Output is correct
31 Correct 2005 ms 69224 KB Output is correct
32 Correct 1524 ms 79504 KB Output is correct
33 Correct 1226 ms 83964 KB Output is correct
34 Correct 6 ms 1100 KB Output is correct
35 Correct 12 ms 1744 KB Output is correct
36 Correct 672 ms 34760 KB Output is correct
37 Correct 452 ms 29592 KB Output is correct
38 Correct 634 ms 39324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 215 ms 17844 KB Output is correct
10 Correct 14 ms 2284 KB Output is correct
11 Correct 220 ms 22084 KB Output is correct
12 Correct 51 ms 6380 KB Output is correct
13 Correct 45 ms 7080 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 4 ms 716 KB Output is correct
16 Correct 535 ms 39968 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 734 ms 42572 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 4 ms 716 KB Output is correct
26 Correct 4 ms 716 KB Output is correct
27 Correct 6 ms 920 KB Output is correct
28 Correct 565 ms 30336 KB Output is correct
29 Correct 901 ms 49240 KB Output is correct
30 Correct 1208 ms 66456 KB Output is correct
31 Correct 1682 ms 81888 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 0 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 0 ms 204 KB Output is correct
37 Correct 0 ms 204 KB Output is correct
38 Correct 0 ms 204 KB Output is correct
39 Correct 0 ms 204 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
41 Correct 0 ms 204 KB Output is correct
42 Correct 0 ms 204 KB Output is correct
43 Correct 3 ms 716 KB Output is correct
44 Correct 4 ms 716 KB Output is correct
45 Correct 579 ms 33368 KB Output is correct
46 Correct 923 ms 48584 KB Output is correct
47 Correct 412 ms 26860 KB Output is correct
48 Correct 0 ms 204 KB Output is correct
49 Correct 0 ms 204 KB Output is correct
50 Correct 0 ms 204 KB Output is correct
51 Correct 0 ms 204 KB Output is correct
52 Correct 0 ms 204 KB Output is correct
53 Correct 0 ms 204 KB Output is correct
54 Correct 0 ms 204 KB Output is correct
55 Incorrect 1554 ms 71980 KB Solution announced impossible, but it is possible.
56 Halted 0 ms 0 KB -