Submission #441450

# Submission time Handle Problem Language Result Execution time Memory
441450 2021-07-05T08:16:20 Z daniel920712 Fountain Parks (IOI21_parks) C++17
55 / 100
1871 ms 84508 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;
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(),i,t,aa,bb,ok=1,xx,yy;
    for(i=0;i<N;i++)
    {
        all[make_pair(x[i],y[i])]=i;
        Father[i]=i;
    }
    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:88:32: warning: 'bb' may be used uninitialized in this function [-Wmaybe-uninitialized]
   88 |             con[make_pair(aa,bb-1)]--;
      |                              ~~^~
parks.cpp:88:34: warning: 'aa' may be used uninitialized in this function [-Wmaybe-uninitialized]
   88 |             con[make_pair(aa,bb-1)]--;
      |                                  ^
# Verdict Execution time Memory Grader output
1 Correct 0 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 515 ms 40032 KB Output is correct
10 Correct 34 ms 4332 KB Output is correct
11 Correct 218 ms 22068 KB Output is correct
12 Correct 51 ms 6340 KB Output is correct
13 Correct 76 ms 12600 KB Output is correct
14 Correct 2 ms 460 KB Output is correct
15 Correct 3 ms 716 KB Output is correct
16 Correct 508 ms 39864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 515 ms 40032 KB Output is correct
10 Correct 34 ms 4332 KB Output is correct
11 Correct 218 ms 22068 KB Output is correct
12 Correct 51 ms 6340 KB Output is correct
13 Correct 76 ms 12600 KB Output is correct
14 Correct 2 ms 460 KB Output is correct
15 Correct 3 ms 716 KB Output is correct
16 Correct 508 ms 39864 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 0 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 1554 ms 81904 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 5 ms 716 KB Output is correct
26 Correct 6 ms 1072 KB Output is correct
27 Correct 8 ms 1356 KB Output is correct
28 Correct 528 ms 30436 KB Output is correct
29 Correct 886 ms 49232 KB Output is correct
30 Correct 1197 ms 66576 KB Output is correct
31 Correct 1583 ms 81896 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 0 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 0 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 5 ms 928 KB Output is correct
45 Correct 532 ms 33424 KB Output is correct
46 Correct 853 ms 48596 KB Output is correct
47 Correct 1008 ms 48612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 515 ms 40032 KB Output is correct
10 Correct 34 ms 4332 KB Output is correct
11 Correct 218 ms 22068 KB Output is correct
12 Correct 51 ms 6340 KB Output is correct
13 Correct 76 ms 12600 KB Output is correct
14 Correct 2 ms 460 KB Output is correct
15 Correct 3 ms 716 KB Output is correct
16 Correct 508 ms 39864 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 0 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 1554 ms 81904 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 5 ms 716 KB Output is correct
26 Correct 6 ms 1072 KB Output is correct
27 Correct 8 ms 1356 KB Output is correct
28 Correct 528 ms 30436 KB Output is correct
29 Correct 886 ms 49232 KB Output is correct
30 Correct 1197 ms 66576 KB Output is correct
31 Correct 1583 ms 81896 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 0 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 0 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 5 ms 928 KB Output is correct
45 Correct 532 ms 33424 KB Output is correct
46 Correct 853 ms 48596 KB Output is correct
47 Correct 1008 ms 48612 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 1 ms 204 KB Output is correct
55 Incorrect 1749 ms 72096 KB Solution announced impossible, but it is possible.
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 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 515 ms 40032 KB Output is correct
10 Correct 34 ms 4332 KB Output is correct
11 Correct 218 ms 22068 KB Output is correct
12 Correct 51 ms 6340 KB Output is correct
13 Correct 76 ms 12600 KB Output is correct
14 Correct 2 ms 460 KB Output is correct
15 Correct 3 ms 716 KB Output is correct
16 Correct 508 ms 39864 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1130 ms 58672 KB Output is correct
21 Correct 1343 ms 57752 KB Output is correct
22 Correct 1269 ms 58480 KB Output is correct
23 Correct 1141 ms 68808 KB Output is correct
24 Correct 356 ms 16608 KB Output is correct
25 Correct 946 ms 54068 KB Output is correct
26 Correct 876 ms 54212 KB Output is correct
27 Correct 1281 ms 82968 KB Output is correct
28 Correct 1294 ms 82908 KB Output is correct
29 Correct 1330 ms 82948 KB Output is correct
30 Correct 1327 ms 83716 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 62 ms 4960 KB Output is correct
33 Correct 107 ms 8408 KB Output is correct
34 Correct 1103 ms 57896 KB Output is correct
35 Correct 20 ms 2380 KB Output is correct
36 Correct 139 ms 11176 KB Output is correct
37 Correct 367 ms 22316 KB Output is correct
38 Correct 509 ms 25392 KB Output is correct
39 Correct 765 ms 34588 KB Output is correct
40 Correct 978 ms 43624 KB Output is correct
41 Correct 1329 ms 53504 KB Output is correct
42 Correct 1582 ms 64508 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 0 ms 204 KB Output is correct
48 Correct 1 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 3 ms 716 KB Output is correct
55 Correct 5 ms 972 KB Output is correct
56 Correct 529 ms 33448 KB Output is correct
57 Correct 838 ms 48528 KB Output is correct
58 Correct 855 ms 48580 KB Output is correct
59 Correct 0 ms 204 KB Output is correct
60 Correct 0 ms 204 KB Output is correct
61 Correct 0 ms 204 KB Output is correct
62 Correct 1173 ms 84508 KB Output is correct
63 Correct 1156 ms 83708 KB Output is correct
64 Correct 1209 ms 82620 KB Output is correct
65 Correct 7 ms 1100 KB Output is correct
66 Correct 14 ms 2080 KB Output is correct
67 Correct 580 ms 33008 KB Output is correct
68 Correct 949 ms 49400 KB Output is correct
69 Correct 1434 ms 68960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 515 ms 40032 KB Output is correct
10 Correct 34 ms 4332 KB Output is correct
11 Correct 218 ms 22068 KB Output is correct
12 Correct 51 ms 6340 KB Output is correct
13 Correct 76 ms 12600 KB Output is correct
14 Correct 2 ms 460 KB Output is correct
15 Correct 3 ms 716 KB Output is correct
16 Correct 508 ms 39864 KB Output is correct
17 Correct 1252 ms 82636 KB Output is correct
18 Correct 1219 ms 82112 KB Output is correct
19 Correct 1146 ms 60248 KB Output is correct
20 Correct 1537 ms 71716 KB Output is correct
21 Correct 1255 ms 70576 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 174 ms 10804 KB Output is correct
24 Correct 47 ms 4936 KB Output is correct
25 Correct 250 ms 16836 KB Output is correct
26 Correct 519 ms 28912 KB Output is correct
27 Correct 801 ms 34664 KB Output is correct
28 Correct 1053 ms 43476 KB Output is correct
29 Correct 1391 ms 52924 KB Output is correct
30 Correct 1597 ms 61440 KB Output is correct
31 Correct 1871 ms 69524 KB Output is correct
32 Correct 1387 ms 79592 KB Output is correct
33 Correct 1173 ms 83712 KB Output is correct
34 Correct 9 ms 1484 KB Output is correct
35 Correct 17 ms 2380 KB Output is correct
36 Correct 626 ms 34940 KB Output is correct
37 Correct 1008 ms 53532 KB Output is correct
38 Correct 1543 ms 73496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 515 ms 40032 KB Output is correct
10 Correct 34 ms 4332 KB Output is correct
11 Correct 218 ms 22068 KB Output is correct
12 Correct 51 ms 6340 KB Output is correct
13 Correct 76 ms 12600 KB Output is correct
14 Correct 2 ms 460 KB Output is correct
15 Correct 3 ms 716 KB Output is correct
16 Correct 508 ms 39864 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 0 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 1554 ms 81904 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 5 ms 716 KB Output is correct
26 Correct 6 ms 1072 KB Output is correct
27 Correct 8 ms 1356 KB Output is correct
28 Correct 528 ms 30436 KB Output is correct
29 Correct 886 ms 49232 KB Output is correct
30 Correct 1197 ms 66576 KB Output is correct
31 Correct 1583 ms 81896 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 0 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 0 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 5 ms 928 KB Output is correct
45 Correct 532 ms 33424 KB Output is correct
46 Correct 853 ms 48596 KB Output is correct
47 Correct 1008 ms 48612 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 1 ms 204 KB Output is correct
55 Incorrect 1749 ms 72096 KB Solution announced impossible, but it is possible.
56 Halted 0 ms 0 KB -