Submission #441444

# Submission time Handle Problem Language Result Execution time Memory
441444 2021-07-05T08:08:23 Z daniel920712 Fountain Parks (IOI21_parks) C++17
30 / 100
767 ms 45712 KB
#include "parks.h"
#include <map>
#include <utility>
#include <queue>
#include <set>
#include <stdio.h>
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 > > have,Not;
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,M;
    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)];
            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;
}

Compilation message

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:22:35: warning: unused variable 'xx' [-Wunused-variable]
   22 |     int N=x.size(),i,t,aa,bb,ok=1,xx,yy,M;
      |                                   ^~
parks.cpp:22:38: warning: unused variable 'yy' [-Wunused-variable]
   22 |     int N=x.size(),i,t,aa,bb,ok=1,xx,yy,M;
      |                                      ^~
# 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 200 ms 17832 KB Output is correct
10 Correct 13 ms 2380 KB Output is correct
11 Correct 75 ms 10400 KB Output is correct
12 Correct 19 ms 3324 KB Output is correct
13 Correct 43 ms 7080 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 190 ms 17816 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 200 ms 17832 KB Output is correct
10 Correct 13 ms 2380 KB Output is correct
11 Correct 75 ms 10400 KB Output is correct
12 Correct 19 ms 3324 KB Output is correct
13 Correct 43 ms 7080 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 190 ms 17816 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 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 689 ms 42480 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 2 ms 540 KB Output is correct
26 Correct 4 ms 716 KB Output is correct
27 Correct 5 ms 972 KB Output is correct
28 Correct 201 ms 17160 KB Output is correct
29 Correct 349 ms 25636 KB Output is correct
30 Correct 568 ms 34148 KB Output is correct
31 Correct 691 ms 42716 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 1 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 2 ms 588 KB Output is correct
44 Correct 3 ms 716 KB Output is correct
45 Correct 223 ms 18548 KB Output is correct
46 Correct 367 ms 26844 KB Output is correct
47 Correct 393 ms 26808 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 200 ms 17832 KB Output is correct
10 Correct 13 ms 2380 KB Output is correct
11 Correct 75 ms 10400 KB Output is correct
12 Correct 19 ms 3324 KB Output is correct
13 Correct 43 ms 7080 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 190 ms 17816 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 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 689 ms 42480 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 2 ms 540 KB Output is correct
26 Correct 4 ms 716 KB Output is correct
27 Correct 5 ms 972 KB Output is correct
28 Correct 201 ms 17160 KB Output is correct
29 Correct 349 ms 25636 KB Output is correct
30 Correct 568 ms 34148 KB Output is correct
31 Correct 691 ms 42716 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 1 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 2 ms 588 KB Output is correct
44 Correct 3 ms 716 KB Output is correct
45 Correct 223 ms 18548 KB Output is correct
46 Correct 367 ms 26844 KB Output is correct
47 Correct 393 ms 26808 KB Output is correct
48 Correct 0 ms 204 KB Output is correct
49 Correct 1 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 0 ms 204 KB Output is correct
55 Correct 767 ms 44972 KB Output is correct
56 Correct 1 ms 204 KB Output is correct
57 Correct 3 ms 716 KB Output is correct
58 Correct 11 ms 1804 KB Output is correct
59 Correct 16 ms 2208 KB Output is correct
60 Correct 290 ms 23192 KB Output is correct
61 Correct 468 ms 31128 KB Output is correct
62 Correct 582 ms 37856 KB Output is correct
63 Correct 742 ms 45712 KB Output is correct
64 Correct 0 ms 204 KB Output is correct
65 Correct 0 ms 204 KB Output is correct
66 Correct 0 ms 204 KB Output is correct
67 Correct 495 ms 36072 KB Output is correct
68 Correct 500 ms 36124 KB Output is correct
69 Correct 492 ms 36000 KB Output is correct
70 Correct 5 ms 844 KB Output is correct
71 Correct 10 ms 1516 KB Output is correct
72 Correct 230 ms 19348 KB Output is correct
73 Correct 376 ms 28544 KB Output is correct
74 Correct 579 ms 37808 KB Output is correct
75 Correct 636 ms 43712 KB Output is correct
76 Correct 481 ms 36288 KB Output is correct
77 Correct 7 ms 1100 KB Output is correct
78 Correct 12 ms 1792 KB Output is correct
79 Correct 237 ms 20356 KB Output is correct
80 Correct 399 ms 30220 KB Output is correct
81 Correct 574 ms 39888 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 200 ms 17832 KB Output is correct
10 Correct 13 ms 2380 KB Output is correct
11 Correct 75 ms 10400 KB Output is correct
12 Correct 19 ms 3324 KB Output is correct
13 Correct 43 ms 7080 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 190 ms 17816 KB Output is correct
17 Incorrect 1 ms 204 KB Given structure is not connected: There is no path between vertices 0 and 1
18 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 200 ms 17832 KB Output is correct
10 Correct 13 ms 2380 KB Output is correct
11 Correct 75 ms 10400 KB Output is correct
12 Correct 19 ms 3324 KB Output is correct
13 Correct 43 ms 7080 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 190 ms 17816 KB Output is correct
17 Incorrect 544 ms 35536 KB Given structure is not connected: There is no path between vertices 0 and 1
18 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 200 ms 17832 KB Output is correct
10 Correct 13 ms 2380 KB Output is correct
11 Correct 75 ms 10400 KB Output is correct
12 Correct 19 ms 3324 KB Output is correct
13 Correct 43 ms 7080 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 190 ms 17816 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 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 689 ms 42480 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 2 ms 540 KB Output is correct
26 Correct 4 ms 716 KB Output is correct
27 Correct 5 ms 972 KB Output is correct
28 Correct 201 ms 17160 KB Output is correct
29 Correct 349 ms 25636 KB Output is correct
30 Correct 568 ms 34148 KB Output is correct
31 Correct 691 ms 42716 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 1 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 2 ms 588 KB Output is correct
44 Correct 3 ms 716 KB Output is correct
45 Correct 223 ms 18548 KB Output is correct
46 Correct 367 ms 26844 KB Output is correct
47 Correct 393 ms 26808 KB Output is correct
48 Correct 0 ms 204 KB Output is correct
49 Correct 1 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 0 ms 204 KB Output is correct
55 Correct 767 ms 44972 KB Output is correct
56 Correct 1 ms 204 KB Output is correct
57 Correct 3 ms 716 KB Output is correct
58 Correct 11 ms 1804 KB Output is correct
59 Correct 16 ms 2208 KB Output is correct
60 Correct 290 ms 23192 KB Output is correct
61 Correct 468 ms 31128 KB Output is correct
62 Correct 582 ms 37856 KB Output is correct
63 Correct 742 ms 45712 KB Output is correct
64 Correct 0 ms 204 KB Output is correct
65 Correct 0 ms 204 KB Output is correct
66 Correct 0 ms 204 KB Output is correct
67 Correct 495 ms 36072 KB Output is correct
68 Correct 500 ms 36124 KB Output is correct
69 Correct 492 ms 36000 KB Output is correct
70 Correct 5 ms 844 KB Output is correct
71 Correct 10 ms 1516 KB Output is correct
72 Correct 230 ms 19348 KB Output is correct
73 Correct 376 ms 28544 KB Output is correct
74 Correct 579 ms 37808 KB Output is correct
75 Correct 636 ms 43712 KB Output is correct
76 Correct 481 ms 36288 KB Output is correct
77 Correct 7 ms 1100 KB Output is correct
78 Correct 12 ms 1792 KB Output is correct
79 Correct 237 ms 20356 KB Output is correct
80 Correct 399 ms 30220 KB Output is correct
81 Correct 574 ms 39888 KB Output is correct
82 Incorrect 1 ms 204 KB Given structure is not connected: There is no path between vertices 0 and 1
83 Halted 0 ms 0 KB -