Submission #617814

# Submission time Handle Problem Language Result Execution time Memory
617814 2022-08-01T14:48:55 Z amunduzbaev Fountain Parks (IOI21_parks) C++17
25 / 100
858 ms 60716 KB
#include "parks.h"

#include "bits/stdc++.h"
using namespace std;

#ifndef EVAL
#include "grader.cpp"
#endif

#define ar array
typedef long long ll;

const int N = 2e5 + 5;
vector<ar<int, 3>> edges[N];

int construct_roads(vector<int> x, vector<int> y) {
	int n = x.size();
	map<ar<int, 2>, int> ss, mm;
	for(int i=0;i<n;i++){
		ss[{x[i], y[i]}] = i;
	}
	
	vector<ar<int, 2>> e, p;
	
	auto add = [&](int a, int b, int p1, int p2){
		edges[a].push_back({b, p1, p2});
		edges[b].push_back({a, p1, p2});
	};
	
	for(int i=0;i<n;i++){
		if(ss.count({x[i] - 2, y[i]})){
			int j = ss[{x[i] - 2, y[i]}];
			e.push_back({i, j});
			p.push_back({-1, -1});
			int u = e.size() - 1;
			if(mm.count({x[i] - 1, y[i] - 1})){
				int v = mm[{x[i] - 1, y[i] - 1}];
				add(u, v, x[i] - 1, y[i] - 1);
				mm.erase({x[i] - 1, y[i] - 1});
			} else {
				mm[{x[i] - 1, y[i] - 1}] = u;
			}
			if(mm.count({x[i] - 1, y[i] + 1})){
				int v = mm[{x[i] - 1, y[i] + 1}];
				add(u, v, x[i] - 1, y[i] + 1);
				mm.erase({x[i] - 1, y[i] + 1});
			} else {
				mm[{x[i] - 1, y[i] + 1}] = u;
			}
		}
		if(ss.count({x[i], y[i] - 2})){
			int j = ss[{x[i], y[i] - 2}];
			e.push_back({i, j});
			p.push_back({-1, -1});
			int u = e.size() - 1;
			if(mm.count({x[i] - 1, y[i] - 1})){
				int v = mm[{x[i] - 1, y[i] - 1}];
				add(u, v, x[i] - 1, y[i] - 1);
				mm.erase({x[i] - 1, y[i] - 1});
			} else {
				mm[{x[i] - 1, y[i] - 1}] = u;
			}
			if(mm.count({x[i] + 1, y[i] - 1})){
				int v = mm[{x[i] + 1, y[i] - 1}];
				add(u, v, x[i] + 1, y[i] - 1);
				mm.erase({x[i] + 1, y[i] - 1});
			} else {
				mm[{x[i] + 1, y[i] - 1}] = u;
			}
		}
	}
	
	int m = e.size();
	if(m != n - 1) return 0;
	assert(m == n - 1);
	for(int i=0;i<m;i++){
		assert((int)edges[i].size() <= 2);
	}
	
	vector<int> used(m);
	function<void(int)> dfs = [&](int i){
		used[i] = 1;
		for(auto [x, p1, p2] : edges[i]){
			if(used[x]) continue;
			p[x] = {p1, p2};
			dfs(x);
		}
	};
	for(auto [x, i] : mm){
		if(used[i]) continue;
		p[i] = x;
		dfs(i);
	}
	
	for(int i=0;i<m;i++){
		if(used[i]) continue;
		p[i] = {edges[i].back()[1], edges[i].back()[2]};
		edges[i].pop_back();
		
		dfs(i);
	}
	
	vector<int> u(m), v(m), A(m), B(m);
	for(int i=0;i<m;i++){
		u[i] = e[i][0], v[i] = e[i][1];
		A[i] = p[i][0], B[i] = p[i][1];
		assert(~A[i] && ~B[i]);
	}
	
	build(u, v, A, B);
	return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 4 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 2 ms 4984 KB Output is correct
9 Correct 309 ms 31944 KB Output is correct
10 Correct 24 ms 7728 KB Output is correct
11 Correct 109 ms 19560 KB Output is correct
12 Correct 27 ms 9012 KB Output is correct
13 Correct 71 ms 14644 KB Output is correct
14 Correct 5 ms 5204 KB Output is correct
15 Correct 6 ms 5432 KB Output is correct
16 Correct 332 ms 32008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 4 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 2 ms 4984 KB Output is correct
9 Correct 309 ms 31944 KB Output is correct
10 Correct 24 ms 7728 KB Output is correct
11 Correct 109 ms 19560 KB Output is correct
12 Correct 27 ms 9012 KB Output is correct
13 Correct 71 ms 14644 KB Output is correct
14 Correct 5 ms 5204 KB Output is correct
15 Correct 6 ms 5432 KB Output is correct
16 Correct 332 ms 32008 KB Output is correct
17 Incorrect 3 ms 4948 KB Solution announced impossible, but it is possible.
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 4 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 2 ms 4984 KB Output is correct
9 Correct 309 ms 31944 KB Output is correct
10 Correct 24 ms 7728 KB Output is correct
11 Correct 109 ms 19560 KB Output is correct
12 Correct 27 ms 9012 KB Output is correct
13 Correct 71 ms 14644 KB Output is correct
14 Correct 5 ms 5204 KB Output is correct
15 Correct 6 ms 5432 KB Output is correct
16 Correct 332 ms 32008 KB Output is correct
17 Incorrect 3 ms 4948 KB Solution announced impossible, but it is possible.
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 4 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 2 ms 4984 KB Output is correct
9 Correct 309 ms 31944 KB Output is correct
10 Correct 24 ms 7728 KB Output is correct
11 Correct 109 ms 19560 KB Output is correct
12 Correct 27 ms 9012 KB Output is correct
13 Correct 71 ms 14644 KB Output is correct
14 Correct 5 ms 5204 KB Output is correct
15 Correct 6 ms 5432 KB Output is correct
16 Correct 332 ms 32008 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 709 ms 54072 KB Output is correct
21 Correct 858 ms 49912 KB Output is correct
22 Correct 704 ms 49852 KB Output is correct
23 Correct 695 ms 52764 KB Output is correct
24 Correct 289 ms 22280 KB Output is correct
25 Correct 725 ms 50268 KB Output is correct
26 Correct 745 ms 50468 KB Output is correct
27 Correct 817 ms 60716 KB Output is correct
28 Correct 817 ms 60540 KB Output is correct
29 Correct 784 ms 60552 KB Output is correct
30 Correct 837 ms 60564 KB Output is correct
31 Correct 3 ms 4948 KB Output is correct
32 Correct 33 ms 8192 KB Output is correct
33 Correct 94 ms 13960 KB Output is correct
34 Correct 726 ms 58820 KB Output is correct
35 Correct 22 ms 6672 KB Output is correct
36 Correct 113 ms 13052 KB Output is correct
37 Correct 278 ms 21216 KB Output is correct
38 Correct 252 ms 22244 KB Output is correct
39 Correct 395 ms 28576 KB Output is correct
40 Correct 542 ms 35264 KB Output is correct
41 Correct 680 ms 41552 KB Output is correct
42 Correct 856 ms 48068 KB Output is correct
43 Correct 2 ms 4948 KB Output is correct
44 Correct 3 ms 4948 KB Output is correct
45 Correct 3 ms 5000 KB Output is correct
46 Correct 3 ms 5000 KB Output is correct
47 Correct 4 ms 4948 KB Output is correct
48 Correct 2 ms 5004 KB Output is correct
49 Correct 3 ms 5000 KB Output is correct
50 Correct 3 ms 4948 KB Output is correct
51 Correct 3 ms 4948 KB Output is correct
52 Correct 3 ms 4936 KB Output is correct
53 Correct 3 ms 4948 KB Output is correct
54 Correct 5 ms 5332 KB Output is correct
55 Correct 7 ms 5460 KB Output is correct
56 Correct 318 ms 28012 KB Output is correct
57 Correct 526 ms 38268 KB Output is correct
58 Correct 518 ms 38348 KB Output is correct
59 Correct 3 ms 4948 KB Output is correct
60 Correct 3 ms 4948 KB Output is correct
61 Correct 2 ms 5004 KB Output is correct
62 Correct 751 ms 60644 KB Output is correct
63 Correct 761 ms 60620 KB Output is correct
64 Correct 764 ms 60512 KB Output is correct
65 Correct 8 ms 5588 KB Output is correct
66 Correct 15 ms 6356 KB Output is correct
67 Correct 327 ms 27120 KB Output is correct
68 Correct 542 ms 38300 KB Output is correct
69 Correct 819 ms 49612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 4 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 2 ms 4984 KB Output is correct
9 Correct 309 ms 31944 KB Output is correct
10 Correct 24 ms 7728 KB Output is correct
11 Correct 109 ms 19560 KB Output is correct
12 Correct 27 ms 9012 KB Output is correct
13 Correct 71 ms 14644 KB Output is correct
14 Correct 5 ms 5204 KB Output is correct
15 Correct 6 ms 5432 KB Output is correct
16 Correct 332 ms 32008 KB Output is correct
17 Incorrect 663 ms 48712 KB Solution announced impossible, but it is possible.
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 4 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 2 ms 4984 KB Output is correct
9 Correct 309 ms 31944 KB Output is correct
10 Correct 24 ms 7728 KB Output is correct
11 Correct 109 ms 19560 KB Output is correct
12 Correct 27 ms 9012 KB Output is correct
13 Correct 71 ms 14644 KB Output is correct
14 Correct 5 ms 5204 KB Output is correct
15 Correct 6 ms 5432 KB Output is correct
16 Correct 332 ms 32008 KB Output is correct
17 Incorrect 3 ms 4948 KB Solution announced impossible, but it is possible.
18 Halted 0 ms 0 KB -