Submission #621036

# Submission time Handle Problem Language Result Execution time Memory
621036 2022-08-03T11:21:01 Z MKopchev Fountain Parks (IOI21_parks) C++17
30 / 100
460 ms 38684 KB
#include "parks.h"
#include<bits/stdc++.h>
using namespace std;

const int nmax=2e5+42;

void build(vector<int> u, vector<int> v, vector<int> a, vector<int> b);

map< pair<int,int>, int > seen;

int ask(int x,int y)
{
    if(seen.count({x,y}))return seen[{x,y}];

    return -1;
}

int parent[nmax];

int root(int node)
{
    if(node==parent[node])return node;

    parent[node]=root(parent[node]);

    return parent[node];
}

set< pair<int,int> > benches;

struct point
{
    int x,y,id;
};

bool cmp(point a,point b)
{
    if(a.x!=b.x)return a.x<b.x;
    return a.y<b.y;
}

point inp[nmax];

int construct_roads(std::vector<int> x, std::vector<int> y) {

    int n=x.size();

    if (n == 1) {
	build({}, {}, {}, {});
        return 1;
    }

    for(int i=0;i<x.size();i++)
        seen[{x[i],y[i]}]=i;

    for(int i=0;i<n;i++)
    {
        parent[i]=i;

        inp[i].x=x[i];
        inp[i].y=y[i];
        inp[i].id=i;
    }

    sort(inp,inp+n,cmp);

    vector<int> u={},v={},a={},b={};

    for(int j=0;j<n;j++)
    {
        int pos=ask(inp[j].x+2,inp[j].y);

        if(pos!=-1&&root(pos)!=root(inp[j].id))
        {
            pair<int,int> bench={inp[j].x+1,inp[j].y-1};

            if(benches.count(bench))bench.second+=2;

            if(benches.count(bench)==0)
            {
                parent[root(pos)]=root(inp[j].id);

                u.push_back(inp[j].id);
                v.push_back(pos);

                a.push_back(bench.first);
                b.push_back(bench.second);

                benches.insert(bench);
            }
        }

        pos=ask(inp[j].x,inp[j].y+2);

        if(pos!=-1&&root(pos)!=root(inp[j].id))
        {
            pair<int,int> bench={inp[j].x-1,inp[j].y+1};

            if(benches.count(bench))bench.first+=2;

            if(benches.count(bench)==0)
            {
                parent[root(pos)]=root(inp[j].id);

                u.push_back(inp[j].id);
                v.push_back(pos);

                a.push_back(bench.first);
                b.push_back(bench.second);

                benches.insert(bench);
            }
        }
    }

    for(int i=0;i<n;i++)
        if(root(i)!=root(0))return 0;

    build(u,v,a,b);

    return 1;
}

/*
static void check(bool cond, string message) {
	if (!cond) {
		printf("%s\n", message.c_str());
		fclose(stdout);
		exit(0);
	}
}

static int n;
static bool build_called;
static int m;
static vector<int> _u, _v, _a, _b;

void build(vector<int> u, vector<int> v, vector<int> a, vector<int> b) {
	check(!build_called, "build is called more than once");
	build_called = true;
	m = u.size();
	check(int(v.size()) == m, "u.size() != v.size()");
	check(int(a.size()) == m, "u.size() != a.size()");
	check(int(b.size()) == m, "u.size() != b.size()");
	_u = u;
	_v = v;
	_a = a;
	_b = b;
}

int main() {
	assert(scanf("%d", &n) == 1);
	vector<int> x(n), y(n);
	for (int i = 0; i < n; i++) {
		assert(scanf("%d%d", &x[i], &y[i]) == 2);
	}
	fclose(stdin);

	build_called = false;
	const int possible = construct_roads(x, y);

	check(possible == 0 || possible == 1, "Invalid return value of construct_roads()");
	if (possible == 1) {
		check(build_called, "construct_roads() returned 1 without calling build()");
	} else {
		check(!build_called, "construct_roads() called build() but returned 0");
	}

	printf("%d\n", possible);
	if (possible == 1) {
		printf("%d\n", m);
		for (int j = 0; j < m; j++) {
			printf("%d %d %d %d\n", _u[j], _v[j], _a[j], _b[j]);
		}
	}
	fclose(stdout);
	return 0;
}
*/

Compilation message

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:53:18: 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=0;i<x.size();i++)
      |                 ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 182 ms 19124 KB Output is correct
10 Correct 13 ms 2376 KB Output is correct
11 Correct 85 ms 10432 KB Output is correct
12 Correct 20 ms 3332 KB Output is correct
13 Correct 53 ms 7136 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 160 ms 19020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 182 ms 19124 KB Output is correct
10 Correct 13 ms 2376 KB Output is correct
11 Correct 85 ms 10432 KB Output is correct
12 Correct 20 ms 3332 KB Output is correct
13 Correct 53 ms 7136 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 160 ms 19020 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 436 ms 37864 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 4 ms 692 KB Output is correct
27 Correct 6 ms 912 KB Output is correct
28 Correct 136 ms 15304 KB Output is correct
29 Correct 302 ms 22836 KB Output is correct
30 Correct 369 ms 30316 KB Output is correct
31 Correct 398 ms 38044 KB Output is correct
32 Correct 1 ms 232 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 2 ms 596 KB Output is correct
44 Correct 3 ms 724 KB Output is correct
45 Correct 178 ms 19024 KB Output is correct
46 Correct 237 ms 27588 KB Output is correct
47 Correct 240 ms 27568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 182 ms 19124 KB Output is correct
10 Correct 13 ms 2376 KB Output is correct
11 Correct 85 ms 10432 KB Output is correct
12 Correct 20 ms 3332 KB Output is correct
13 Correct 53 ms 7136 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 160 ms 19020 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 436 ms 37864 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 4 ms 692 KB Output is correct
27 Correct 6 ms 912 KB Output is correct
28 Correct 136 ms 15304 KB Output is correct
29 Correct 302 ms 22836 KB Output is correct
30 Correct 369 ms 30316 KB Output is correct
31 Correct 398 ms 38044 KB Output is correct
32 Correct 1 ms 232 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 2 ms 596 KB Output is correct
44 Correct 3 ms 724 KB Output is correct
45 Correct 178 ms 19024 KB Output is correct
46 Correct 237 ms 27588 KB Output is correct
47 Correct 240 ms 27568 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 460 ms 37848 KB Output is correct
56 Correct 1 ms 260 KB Output is correct
57 Correct 2 ms 596 KB Output is correct
58 Correct 7 ms 1492 KB Output is correct
59 Correct 11 ms 1892 KB Output is correct
60 Correct 173 ms 19080 KB Output is correct
61 Correct 269 ms 25616 KB Output is correct
62 Correct 351 ms 31284 KB Output is correct
63 Correct 452 ms 37908 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 0 ms 212 KB Output is correct
67 Correct 371 ms 37868 KB Output is correct
68 Correct 402 ms 37964 KB Output is correct
69 Correct 375 ms 37720 KB Output is correct
70 Correct 4 ms 852 KB Output is correct
71 Correct 8 ms 1492 KB Output is correct
72 Correct 162 ms 19024 KB Output is correct
73 Correct 246 ms 28544 KB Output is correct
74 Correct 367 ms 37908 KB Output is correct
75 Correct 364 ms 37868 KB Output is correct
76 Correct 370 ms 37912 KB Output is correct
77 Correct 6 ms 1108 KB Output is correct
78 Correct 13 ms 1752 KB Output is correct
79 Correct 164 ms 19024 KB Output is correct
80 Correct 245 ms 28444 KB Output is correct
81 Correct 352 ms 37920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 182 ms 19124 KB Output is correct
10 Correct 13 ms 2376 KB Output is correct
11 Correct 85 ms 10432 KB Output is correct
12 Correct 20 ms 3332 KB Output is correct
13 Correct 53 ms 7136 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 160 ms 19020 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 371 ms 38684 KB Output is correct
21 Correct 368 ms 37980 KB Output is correct
22 Correct 401 ms 38208 KB Output is correct
23 Correct 328 ms 32288 KB Output is correct
24 Correct 203 ms 19088 KB Output is correct
25 Correct 313 ms 31584 KB Output is correct
26 Correct 321 ms 31568 KB Output is correct
27 Correct 359 ms 37932 KB Output is correct
28 Correct 389 ms 37912 KB Output is correct
29 Correct 358 ms 37832 KB Output is correct
30 Correct 391 ms 37816 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Incorrect 14 ms 2516 KB Solution announced impossible, but it is possible.
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 182 ms 19124 KB Output is correct
10 Correct 13 ms 2376 KB Output is correct
11 Correct 85 ms 10432 KB Output is correct
12 Correct 20 ms 3332 KB Output is correct
13 Correct 53 ms 7136 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 160 ms 19020 KB Output is correct
17 Correct 353 ms 37900 KB Output is correct
18 Correct 386 ms 37820 KB Output is correct
19 Correct 363 ms 38280 KB Output is correct
20 Correct 349 ms 37112 KB Output is correct
21 Correct 288 ms 33248 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Incorrect 34 ms 5156 KB Solution announced impossible, but it is possible.
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 182 ms 19124 KB Output is correct
10 Correct 13 ms 2376 KB Output is correct
11 Correct 85 ms 10432 KB Output is correct
12 Correct 20 ms 3332 KB Output is correct
13 Correct 53 ms 7136 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 160 ms 19020 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 436 ms 37864 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 4 ms 692 KB Output is correct
27 Correct 6 ms 912 KB Output is correct
28 Correct 136 ms 15304 KB Output is correct
29 Correct 302 ms 22836 KB Output is correct
30 Correct 369 ms 30316 KB Output is correct
31 Correct 398 ms 38044 KB Output is correct
32 Correct 1 ms 232 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 2 ms 596 KB Output is correct
44 Correct 3 ms 724 KB Output is correct
45 Correct 178 ms 19024 KB Output is correct
46 Correct 237 ms 27588 KB Output is correct
47 Correct 240 ms 27568 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 460 ms 37848 KB Output is correct
56 Correct 1 ms 260 KB Output is correct
57 Correct 2 ms 596 KB Output is correct
58 Correct 7 ms 1492 KB Output is correct
59 Correct 11 ms 1892 KB Output is correct
60 Correct 173 ms 19080 KB Output is correct
61 Correct 269 ms 25616 KB Output is correct
62 Correct 351 ms 31284 KB Output is correct
63 Correct 452 ms 37908 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 0 ms 212 KB Output is correct
67 Correct 371 ms 37868 KB Output is correct
68 Correct 402 ms 37964 KB Output is correct
69 Correct 375 ms 37720 KB Output is correct
70 Correct 4 ms 852 KB Output is correct
71 Correct 8 ms 1492 KB Output is correct
72 Correct 162 ms 19024 KB Output is correct
73 Correct 246 ms 28544 KB Output is correct
74 Correct 367 ms 37908 KB Output is correct
75 Correct 364 ms 37868 KB Output is correct
76 Correct 370 ms 37912 KB Output is correct
77 Correct 6 ms 1108 KB Output is correct
78 Correct 13 ms 1752 KB Output is correct
79 Correct 164 ms 19024 KB Output is correct
80 Correct 245 ms 28444 KB Output is correct
81 Correct 352 ms 37920 KB Output is correct
82 Correct 0 ms 212 KB Output is correct
83 Correct 0 ms 212 KB Output is correct
84 Correct 1 ms 212 KB Output is correct
85 Correct 371 ms 38684 KB Output is correct
86 Correct 368 ms 37980 KB Output is correct
87 Correct 401 ms 38208 KB Output is correct
88 Correct 328 ms 32288 KB Output is correct
89 Correct 203 ms 19088 KB Output is correct
90 Correct 313 ms 31584 KB Output is correct
91 Correct 321 ms 31568 KB Output is correct
92 Correct 359 ms 37932 KB Output is correct
93 Correct 389 ms 37912 KB Output is correct
94 Correct 358 ms 37832 KB Output is correct
95 Correct 391 ms 37816 KB Output is correct
96 Correct 0 ms 212 KB Output is correct
97 Incorrect 14 ms 2516 KB Solution announced impossible, but it is possible.
98 Halted 0 ms 0 KB -