Submission #481505

# Submission time Handle Problem Language Result Execution time Memory
481505 2021-10-21T05:00:06 Z 8e7 Fountain Parks (IOI21_parks) C++17
15 / 100
126 ms 17852 KB
//Challenge: Accepted
#include "parks.h"
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
using namespace std;
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ...b) {
	cout << a << " ", debug(b ...);
};
template<class T> void pary (T l, T r) {
	while (l!= r) cout << *l << " ", l++;
	cout << endl;
};
#define ll long long
#define maxn 200005
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
struct pnt{
	int x, y, id;
	pnt(){x = y = id = 0;}
	pnt(int a, int b, int c){x = a, y = b, id = c;}
};
int par[maxn];
int find(int a) {
	return a == par[a] ? a : par[a] = find(par[a]);
}
int num = 0;
bool Union (int a, int b) {
	//debug(a, b);
	a = find(a), b = find(b);
	if (a == b) return false;
	//debug(1);
	num--;
	par[find(a)] = find(b);
	return true;
}
int construct_roads(std::vector<int> x, std::vector<int> y) {
	int n = x.size();
	for (int i = 0;i < n;i++) par[i] = i;
	num = n;
	vector<pnt> a, b;
	for (int i = 0;i < n;i++) {
		if (x[i] == 2)a.push_back(pnt(y[i], x[i], i));
		else b.push_back(pnt(y[i], x[i], i));
	}
    if (x.size() == 1) {
		build({}, {}, {}, {});
        return 1;
    }
	sort(a.begin(), a.end(), [&](pnt p, pnt q){return (p.x == q.x ? p.y < q.y : p.x < q.x);});
	sort(b.begin(), b.end(), [&](pnt p, pnt q){return (p.x == q.x ? p.y < q.y : p.x < q.x);});
    vector<int> u, v, ax, ay;
	int id = 0;
	for (int i = 0;i < a.size();i++) {
		while (id < b.size() && b[id].x < a[i].x) id++;
		if (i && a[i].x - a[i-1].x == 2) {
			if (Union(a[i].id, a[i-1].id)) {
				u.push_back(a[i].id), v.push_back(a[i-1].id);
				ax.push_back(a[i].x - 1), ay.push_back(a[i].y - 1);
			}	
		}
		if (id < b.size() && a[i].x == b[id].x) {
			if (Union(a[i].id, b[id].id)) {
				u.push_back(a[i].id), v.push_back(b[id].id);
				ax.push_back(a[i].x - 1), ay.push_back(a[i].y + 1);
			}
		}
	}	
	for (int i = 1;i < b.size();i++) {
		if (b[i].x - b[i-1].x == 2) {
			if (Union(b[i].id, b[i-1].id)) {
				u.push_back(b[i].id), v.push_back(b[i-1].id);
				ax.push_back(b[i].x - 1), ay.push_back(b[i].y + 1);
			}
		}
	}
	if (num > 1) return 0;
	build(u, v, ay, ax);
    return 1;
}
/*
5
2 2
4 2
4 4
4 6
2 6
*/

Compilation message

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:58:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<pnt>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |  for (int i = 0;i < a.size();i++) {
      |                 ~~^~~~~~~~~~
parks.cpp:59:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<pnt>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |   while (id < b.size() && b[id].x < a[i].x) id++;
      |          ~~~^~~~~~~~~~
parks.cpp:66:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<pnt>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |   if (id < b.size() && a[i].x == b[id].x) {
      |       ~~~^~~~~~~~~~
parks.cpp:73:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<pnt>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |  for (int i = 1;i < b.size();i++) {
      |                 ~~^~~~~~~~~~
# 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 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 59 ms 8524 KB Output is correct
10 Correct 5 ms 1176 KB Output is correct
11 Correct 27 ms 4656 KB Output is correct
12 Correct 12 ms 1504 KB Output is correct
13 Correct 9 ms 3016 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 67 ms 8568 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 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 59 ms 8524 KB Output is correct
10 Correct 5 ms 1176 KB Output is correct
11 Correct 27 ms 4656 KB Output is correct
12 Correct 12 ms 1504 KB Output is correct
13 Correct 9 ms 3016 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 67 ms 8568 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 260 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 126 ms 17852 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 460 KB Output is correct
27 Correct 1 ms 460 KB Output is correct
28 Correct 51 ms 7356 KB Output is correct
29 Correct 75 ms 10448 KB Output is correct
30 Correct 93 ms 14508 KB Output is correct
31 Correct 117 ms 17808 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 1 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 1 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 1 ms 332 KB Output is correct
44 Correct 2 ms 460 KB Output is correct
45 Correct 64 ms 8484 KB Output is correct
46 Correct 84 ms 12460 KB Output is correct
47 Correct 83 ms 12548 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 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 59 ms 8524 KB Output is correct
10 Correct 5 ms 1176 KB Output is correct
11 Correct 27 ms 4656 KB Output is correct
12 Correct 12 ms 1504 KB Output is correct
13 Correct 9 ms 3016 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 67 ms 8568 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 260 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 126 ms 17852 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 460 KB Output is correct
27 Correct 1 ms 460 KB Output is correct
28 Correct 51 ms 7356 KB Output is correct
29 Correct 75 ms 10448 KB Output is correct
30 Correct 93 ms 14508 KB Output is correct
31 Correct 117 ms 17808 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 1 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 1 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 1 ms 332 KB Output is correct
44 Correct 2 ms 460 KB Output is correct
45 Correct 64 ms 8484 KB Output is correct
46 Correct 84 ms 12460 KB Output is correct
47 Correct 83 ms 12548 KB Output is correct
48 Incorrect 0 ms 204 KB Solution announced impossible, but it is possible.
49 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 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 59 ms 8524 KB Output is correct
10 Correct 5 ms 1176 KB Output is correct
11 Correct 27 ms 4656 KB Output is correct
12 Correct 12 ms 1504 KB Output is correct
13 Correct 9 ms 3016 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 67 ms 8568 KB Output is correct
17 Incorrect 0 ms 204 KB Solution announced impossible, but it is possible.
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 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 59 ms 8524 KB Output is correct
10 Correct 5 ms 1176 KB Output is correct
11 Correct 27 ms 4656 KB Output is correct
12 Correct 12 ms 1504 KB Output is correct
13 Correct 9 ms 3016 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 67 ms 8568 KB Output is correct
17 Incorrect 59 ms 9516 KB Solution announced impossible, but it is possible.
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 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 59 ms 8524 KB Output is correct
10 Correct 5 ms 1176 KB Output is correct
11 Correct 27 ms 4656 KB Output is correct
12 Correct 12 ms 1504 KB Output is correct
13 Correct 9 ms 3016 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 67 ms 8568 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 260 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 126 ms 17852 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 460 KB Output is correct
27 Correct 1 ms 460 KB Output is correct
28 Correct 51 ms 7356 KB Output is correct
29 Correct 75 ms 10448 KB Output is correct
30 Correct 93 ms 14508 KB Output is correct
31 Correct 117 ms 17808 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 1 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 1 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 1 ms 332 KB Output is correct
44 Correct 2 ms 460 KB Output is correct
45 Correct 64 ms 8484 KB Output is correct
46 Correct 84 ms 12460 KB Output is correct
47 Correct 83 ms 12548 KB Output is correct
48 Incorrect 0 ms 204 KB Solution announced impossible, but it is possible.
49 Halted 0 ms 0 KB -