Submission #441586

# Submission time Handle Problem Language Result Execution time Memory
441586 2021-07-05T13:16:32 Z azberjibiou Fountain Parks (IOI21_parks) C++17
55 / 100
1913 ms 2097156 KB
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define pii pair<int, int>
const int mxN=800020;
typedef struct pnt{
    int fir, sec, idx;
}pnt;
typedef struct edge{
    int nxt, p1, p2;
}edge;
int N;
vector <pii> coor;
vector <edge> adj[mxN];
pnt A[mxN];
int par[mxN];
bool Chk[mxN];
vector <int> u, v, a, b;
bool cmp1(pnt a, pnt b)
{
    if(a.fir!=b.fir)    return a.fir<b.fir;
    return a.sec<b.sec;
}
bool cmp2(pnt a, pnt b)
{
    if(a.sec!=b.sec)    return a.sec<b.sec;
    return a.fir<b.fir;
}
int findpar(int a)
{
    return (par[a]==a ? a : par[a]=findpar(par[a]));
}
void onion(int a, int b)
{
    int p=findpar(a), q=findpar(b);
    if(p!=q)    par[p]=q;
}
void dfs1(int now, int pre)
{
    Chk[now]=true;
    for(auto ele : adj[now])  if(ele.nxt!=pre)
    {
        u.push_back(ele.p1);   v.push_back(ele.p2);
        a.push_back(coor[ele.nxt].fir); b.push_back(coor[ele.nxt].sec);
        dfs1(ele.nxt, now);
    }
}
void dfs2(int now, int pre, int s)
{
    //printf("now=%d\n", now);
    Chk[now]=true;
    for(auto ele : adj[now])    if(ele.nxt!=pre)
    {
        u.push_back(ele.p1);   v.push_back(ele.p2);
        a.push_back(coor[now].fir); b.push_back(coor[now].sec);
        if(ele.nxt==s)  return;
        dfs2(ele.nxt, now, s);
        if(now==s)  return;
    }
}
int construct_roads(std::vector<int> x, std::vector<int> y) {
    N=x.size();
    for(int i=0;i<N;i++)    A[i].fir=x[i], A[i].sec=y[i], A[i].idx=i;
    for(int i=0;i<N;i++)    par[i]=i;
    sort(A, A+N, cmp1);
    for(int i=1;i<N;i++)
    {
        if(A[i-1].fir==A[i].fir && A[i-1].sec==A[i].sec-2)
        {
            onion(A[i-1].idx, A[i].idx);
            coor.push_back({A[i].fir+1, A[i].sec-1});
            coor.push_back({A[i].fir-1, A[i].sec-1});
        }
    }
    sort(A, A+N, cmp2);
    for(int i=1;i<N;i++)
    {
        if(A[i-1].sec==A[i].sec && A[i-1].fir==A[i].fir-2)
        {
            onion(A[i-1].idx, A[i].idx);
            coor.push_back({A[i].fir-1, A[i].sec-1});
            coor.push_back({A[i].fir-1, A[i].sec+1});
        }
    }
    for(int i=1;i<N;i++)    if(findpar(i)!=findpar(i-1))    return 0;
    sort(coor.begin(), coor.end());
    coor.erase(unique(coor.begin(), coor.end()), coor.end());
    sort(A, A+N, cmp1);
    for(int i=1;i<N;i++)
    {
        if(A[i-1].fir==A[i].fir && A[i-1].sec==A[i].sec-2)
        {
            pii tmp1={A[i].fir+1, A[i].sec-1}, tmp2={A[i].fir-1, A[i].sec-1};
            int t1=lower_bound(coor.begin(), coor.end(), tmp1)-coor.begin();
            int t2=lower_bound(coor.begin(), coor.end(), tmp2)-coor.begin();
            adj[t1].push_back({t2, A[i-1].idx, A[i].idx});
            adj[t2].push_back({t1, A[i-1].idx, A[i].idx});
        }
    }
    sort(A, A+N, cmp2);
    for(int i=1;i<N;i++)
    {
        if(A[i-1].sec==A[i].sec && A[i-1].fir==A[i].fir-2)
        {
            pii tmp1={A[i].fir-1, A[i].sec-1}, tmp2={A[i].fir-1, A[i].sec+1};
            int t1=lower_bound(coor.begin(), coor.end(), tmp1)-coor.begin();
            int t2=lower_bound(coor.begin(), coor.end(), tmp2)-coor.begin();
            adj[t1].push_back({t2, A[i-1].idx, A[i].idx});
            adj[t2].push_back({t1, A[i-1].idx, A[i].idx});
        }
    }
    for(int i=0;i<coor.size();i++)
    {
        if(!Chk[i] && adj[i].size()==1)
        {
            dfs1(i, -1);
        }
    }
    for(int i=0;i<coor.size();i++)
    {
        if(!Chk[i])
        {
            dfs2(i, -1, i);
        }
    }
    build(u, v, a, b);
    return 1;
}

Compilation message

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:114:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  114 |     for(int i=0;i<coor.size();i++)
      |                 ~^~~~~~~~~~~~
parks.cpp:121:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  121 |     for(int i=0;i<coor.size();i++)
      |                 ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 13 ms 19020 KB Output is correct
2 Correct 14 ms 19076 KB Output is correct
3 Correct 14 ms 19104 KB Output is correct
4 Correct 12 ms 19020 KB Output is correct
5 Correct 13 ms 19020 KB Output is correct
6 Correct 13 ms 18996 KB Output is correct
7 Correct 12 ms 18980 KB Output is correct
8 Correct 14 ms 19020 KB Output is correct
9 Correct 148 ms 37508 KB Output is correct
10 Correct 25 ms 21028 KB Output is correct
11 Correct 83 ms 28944 KB Output is correct
12 Correct 30 ms 21892 KB Output is correct
13 Correct 29 ms 21616 KB Output is correct
14 Correct 14 ms 19148 KB Output is correct
15 Correct 15 ms 19184 KB Output is correct
16 Correct 155 ms 37304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 19020 KB Output is correct
2 Correct 14 ms 19076 KB Output is correct
3 Correct 14 ms 19104 KB Output is correct
4 Correct 12 ms 19020 KB Output is correct
5 Correct 13 ms 19020 KB Output is correct
6 Correct 13 ms 18996 KB Output is correct
7 Correct 12 ms 18980 KB Output is correct
8 Correct 14 ms 19020 KB Output is correct
9 Correct 148 ms 37508 KB Output is correct
10 Correct 25 ms 21028 KB Output is correct
11 Correct 83 ms 28944 KB Output is correct
12 Correct 30 ms 21892 KB Output is correct
13 Correct 29 ms 21616 KB Output is correct
14 Correct 14 ms 19148 KB Output is correct
15 Correct 15 ms 19184 KB Output is correct
16 Correct 155 ms 37304 KB Output is correct
17 Correct 13 ms 19096 KB Output is correct
18 Correct 12 ms 19072 KB Output is correct
19 Correct 13 ms 19020 KB Output is correct
20 Correct 13 ms 19020 KB Output is correct
21 Correct 13 ms 19008 KB Output is correct
22 Correct 13 ms 19080 KB Output is correct
23 Correct 458 ms 71580 KB Output is correct
24 Correct 13 ms 19020 KB Output is correct
25 Correct 15 ms 19404 KB Output is correct
26 Correct 14 ms 19408 KB Output is correct
27 Correct 15 ms 19424 KB Output is correct
28 Correct 177 ms 39208 KB Output is correct
29 Correct 288 ms 50388 KB Output is correct
30 Correct 369 ms 59804 KB Output is correct
31 Correct 459 ms 71608 KB Output is correct
32 Correct 13 ms 19024 KB Output is correct
33 Correct 14 ms 19044 KB Output is correct
34 Correct 13 ms 19020 KB Output is correct
35 Correct 13 ms 19020 KB Output is correct
36 Correct 13 ms 19020 KB Output is correct
37 Correct 15 ms 19040 KB Output is correct
38 Correct 14 ms 19000 KB Output is correct
39 Correct 12 ms 19040 KB Output is correct
40 Correct 15 ms 19020 KB Output is correct
41 Correct 15 ms 19100 KB Output is correct
42 Correct 15 ms 19060 KB Output is correct
43 Correct 13 ms 19164 KB Output is correct
44 Correct 14 ms 19240 KB Output is correct
45 Correct 179 ms 34628 KB Output is correct
46 Correct 274 ms 42624 KB Output is correct
47 Correct 258 ms 42548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 19020 KB Output is correct
2 Correct 14 ms 19076 KB Output is correct
3 Correct 14 ms 19104 KB Output is correct
4 Correct 12 ms 19020 KB Output is correct
5 Correct 13 ms 19020 KB Output is correct
6 Correct 13 ms 18996 KB Output is correct
7 Correct 12 ms 18980 KB Output is correct
8 Correct 14 ms 19020 KB Output is correct
9 Correct 148 ms 37508 KB Output is correct
10 Correct 25 ms 21028 KB Output is correct
11 Correct 83 ms 28944 KB Output is correct
12 Correct 30 ms 21892 KB Output is correct
13 Correct 29 ms 21616 KB Output is correct
14 Correct 14 ms 19148 KB Output is correct
15 Correct 15 ms 19184 KB Output is correct
16 Correct 155 ms 37304 KB Output is correct
17 Correct 13 ms 19096 KB Output is correct
18 Correct 12 ms 19072 KB Output is correct
19 Correct 13 ms 19020 KB Output is correct
20 Correct 13 ms 19020 KB Output is correct
21 Correct 13 ms 19008 KB Output is correct
22 Correct 13 ms 19080 KB Output is correct
23 Correct 458 ms 71580 KB Output is correct
24 Correct 13 ms 19020 KB Output is correct
25 Correct 15 ms 19404 KB Output is correct
26 Correct 14 ms 19408 KB Output is correct
27 Correct 15 ms 19424 KB Output is correct
28 Correct 177 ms 39208 KB Output is correct
29 Correct 288 ms 50388 KB Output is correct
30 Correct 369 ms 59804 KB Output is correct
31 Correct 459 ms 71608 KB Output is correct
32 Correct 13 ms 19024 KB Output is correct
33 Correct 14 ms 19044 KB Output is correct
34 Correct 13 ms 19020 KB Output is correct
35 Correct 13 ms 19020 KB Output is correct
36 Correct 13 ms 19020 KB Output is correct
37 Correct 15 ms 19040 KB Output is correct
38 Correct 14 ms 19000 KB Output is correct
39 Correct 12 ms 19040 KB Output is correct
40 Correct 15 ms 19020 KB Output is correct
41 Correct 15 ms 19100 KB Output is correct
42 Correct 15 ms 19060 KB Output is correct
43 Correct 13 ms 19164 KB Output is correct
44 Correct 14 ms 19240 KB Output is correct
45 Correct 179 ms 34628 KB Output is correct
46 Correct 274 ms 42624 KB Output is correct
47 Correct 258 ms 42548 KB Output is correct
48 Correct 13 ms 19004 KB Output is correct
49 Correct 13 ms 19020 KB Output is correct
50 Correct 13 ms 19068 KB Output is correct
51 Runtime error 1913 ms 2097156 KB Execution killed with signal 9
52 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 19020 KB Output is correct
2 Correct 14 ms 19076 KB Output is correct
3 Correct 14 ms 19104 KB Output is correct
4 Correct 12 ms 19020 KB Output is correct
5 Correct 13 ms 19020 KB Output is correct
6 Correct 13 ms 18996 KB Output is correct
7 Correct 12 ms 18980 KB Output is correct
8 Correct 14 ms 19020 KB Output is correct
9 Correct 148 ms 37508 KB Output is correct
10 Correct 25 ms 21028 KB Output is correct
11 Correct 83 ms 28944 KB Output is correct
12 Correct 30 ms 21892 KB Output is correct
13 Correct 29 ms 21616 KB Output is correct
14 Correct 14 ms 19148 KB Output is correct
15 Correct 15 ms 19184 KB Output is correct
16 Correct 155 ms 37304 KB Output is correct
17 Correct 14 ms 19020 KB Output is correct
18 Correct 13 ms 19096 KB Output is correct
19 Correct 14 ms 19012 KB Output is correct
20 Correct 330 ms 64676 KB Output is correct
21 Correct 337 ms 56720 KB Output is correct
22 Correct 343 ms 56600 KB Output is correct
23 Correct 275 ms 50700 KB Output is correct
24 Correct 110 ms 26416 KB Output is correct
25 Correct 138 ms 30644 KB Output is correct
26 Correct 117 ms 30732 KB Output is correct
27 Correct 333 ms 55400 KB Output is correct
28 Correct 342 ms 55432 KB Output is correct
29 Correct 386 ms 55352 KB Output is correct
30 Correct 393 ms 55304 KB Output is correct
31 Correct 13 ms 19020 KB Output is correct
32 Correct 35 ms 21484 KB Output is correct
33 Correct 58 ms 23492 KB Output is correct
34 Correct 334 ms 65696 KB Output is correct
35 Correct 18 ms 19872 KB Output is correct
36 Correct 44 ms 22332 KB Output is correct
37 Correct 69 ms 25624 KB Output is correct
38 Correct 157 ms 32748 KB Output is correct
39 Correct 217 ms 36884 KB Output is correct
40 Correct 273 ms 42652 KB Output is correct
41 Correct 330 ms 46904 KB Output is correct
42 Correct 392 ms 51152 KB Output is correct
43 Correct 13 ms 19068 KB Output is correct
44 Correct 12 ms 19032 KB Output is correct
45 Correct 12 ms 19056 KB Output is correct
46 Correct 13 ms 19088 KB Output is correct
47 Correct 13 ms 18988 KB Output is correct
48 Correct 13 ms 19020 KB Output is correct
49 Correct 13 ms 19020 KB Output is correct
50 Correct 13 ms 19020 KB Output is correct
51 Correct 13 ms 19104 KB Output is correct
52 Correct 12 ms 19096 KB Output is correct
53 Correct 12 ms 19088 KB Output is correct
54 Correct 13 ms 19172 KB Output is correct
55 Correct 14 ms 19240 KB Output is correct
56 Correct 173 ms 35456 KB Output is correct
57 Correct 262 ms 43888 KB Output is correct
58 Correct 258 ms 43684 KB Output is correct
59 Correct 13 ms 19020 KB Output is correct
60 Correct 13 ms 18996 KB Output is correct
61 Correct 12 ms 18992 KB Output is correct
62 Correct 364 ms 56156 KB Output is correct
63 Correct 357 ms 56588 KB Output is correct
64 Correct 358 ms 55828 KB Output is correct
65 Correct 14 ms 19276 KB Output is correct
66 Correct 16 ms 19680 KB Output is correct
67 Correct 163 ms 35180 KB Output is correct
68 Correct 257 ms 44260 KB Output is correct
69 Correct 327 ms 51212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 19020 KB Output is correct
2 Correct 14 ms 19076 KB Output is correct
3 Correct 14 ms 19104 KB Output is correct
4 Correct 12 ms 19020 KB Output is correct
5 Correct 13 ms 19020 KB Output is correct
6 Correct 13 ms 18996 KB Output is correct
7 Correct 12 ms 18980 KB Output is correct
8 Correct 14 ms 19020 KB Output is correct
9 Correct 148 ms 37508 KB Output is correct
10 Correct 25 ms 21028 KB Output is correct
11 Correct 83 ms 28944 KB Output is correct
12 Correct 30 ms 21892 KB Output is correct
13 Correct 29 ms 21616 KB Output is correct
14 Correct 14 ms 19148 KB Output is correct
15 Correct 15 ms 19184 KB Output is correct
16 Correct 155 ms 37304 KB Output is correct
17 Correct 375 ms 56204 KB Output is correct
18 Correct 352 ms 56456 KB Output is correct
19 Correct 344 ms 71484 KB Output is correct
20 Correct 395 ms 55080 KB Output is correct
21 Correct 349 ms 51476 KB Output is correct
22 Correct 12 ms 19020 KB Output is correct
23 Correct 69 ms 25100 KB Output is correct
24 Correct 22 ms 20544 KB Output is correct
25 Correct 51 ms 24352 KB Output is correct
26 Correct 80 ms 28408 KB Output is correct
27 Correct 218 ms 37428 KB Output is correct
28 Correct 265 ms 43088 KB Output is correct
29 Correct 324 ms 47124 KB Output is correct
30 Correct 378 ms 50800 KB Output is correct
31 Correct 431 ms 54856 KB Output is correct
32 Correct 364 ms 56540 KB Output is correct
33 Correct 374 ms 56540 KB Output is correct
34 Correct 15 ms 19496 KB Output is correct
35 Correct 17 ms 19788 KB Output is correct
36 Correct 168 ms 36224 KB Output is correct
37 Correct 253 ms 45844 KB Output is correct
38 Correct 347 ms 53380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 19020 KB Output is correct
2 Correct 14 ms 19076 KB Output is correct
3 Correct 14 ms 19104 KB Output is correct
4 Correct 12 ms 19020 KB Output is correct
5 Correct 13 ms 19020 KB Output is correct
6 Correct 13 ms 18996 KB Output is correct
7 Correct 12 ms 18980 KB Output is correct
8 Correct 14 ms 19020 KB Output is correct
9 Correct 148 ms 37508 KB Output is correct
10 Correct 25 ms 21028 KB Output is correct
11 Correct 83 ms 28944 KB Output is correct
12 Correct 30 ms 21892 KB Output is correct
13 Correct 29 ms 21616 KB Output is correct
14 Correct 14 ms 19148 KB Output is correct
15 Correct 15 ms 19184 KB Output is correct
16 Correct 155 ms 37304 KB Output is correct
17 Correct 13 ms 19096 KB Output is correct
18 Correct 12 ms 19072 KB Output is correct
19 Correct 13 ms 19020 KB Output is correct
20 Correct 13 ms 19020 KB Output is correct
21 Correct 13 ms 19008 KB Output is correct
22 Correct 13 ms 19080 KB Output is correct
23 Correct 458 ms 71580 KB Output is correct
24 Correct 13 ms 19020 KB Output is correct
25 Correct 15 ms 19404 KB Output is correct
26 Correct 14 ms 19408 KB Output is correct
27 Correct 15 ms 19424 KB Output is correct
28 Correct 177 ms 39208 KB Output is correct
29 Correct 288 ms 50388 KB Output is correct
30 Correct 369 ms 59804 KB Output is correct
31 Correct 459 ms 71608 KB Output is correct
32 Correct 13 ms 19024 KB Output is correct
33 Correct 14 ms 19044 KB Output is correct
34 Correct 13 ms 19020 KB Output is correct
35 Correct 13 ms 19020 KB Output is correct
36 Correct 13 ms 19020 KB Output is correct
37 Correct 15 ms 19040 KB Output is correct
38 Correct 14 ms 19000 KB Output is correct
39 Correct 12 ms 19040 KB Output is correct
40 Correct 15 ms 19020 KB Output is correct
41 Correct 15 ms 19100 KB Output is correct
42 Correct 15 ms 19060 KB Output is correct
43 Correct 13 ms 19164 KB Output is correct
44 Correct 14 ms 19240 KB Output is correct
45 Correct 179 ms 34628 KB Output is correct
46 Correct 274 ms 42624 KB Output is correct
47 Correct 258 ms 42548 KB Output is correct
48 Correct 13 ms 19004 KB Output is correct
49 Correct 13 ms 19020 KB Output is correct
50 Correct 13 ms 19068 KB Output is correct
51 Runtime error 1913 ms 2097156 KB Execution killed with signal 9
52 Halted 0 ms 0 KB -