Submission #1046608

# Submission time Handle Problem Language Result Execution time Memory
1046608 2024-08-06T18:00:03 Z Unforgettablepl Fountain Parks (IOI21_parks) C++17
45 / 100
909 ms 108740 KB
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;

int construct_roads(vector<int> x,vector<int> y){
	int n = x.size();
	map<pair<int,int>,int> lookup;
	for(int i=0;i<n;i++)lookup[{x[i],y[i]}]=i;
	vector<int> u,v,a,b;
	vector<vector<int>> adj(1);
	vector<vector<int>> adjsepar(n);
	vector<tuple<int,int,int,int>> edges;
	edges.emplace_back(0,0,0,0);
	int S = 0;
	for(int i=0;i<n;i++){
		if(lookup.count({x[i]+2,y[i]})){
			adjsepar[i].emplace_back(lookup[{x[i]+2,y[i]}]);
			adjsepar[lookup[{x[i]+2,y[i]}]].emplace_back(i);
			S++;
			adj.emplace_back();
			edges.emplace_back(i,lookup[{x[i]+2,y[i]}],x[i]+1,y[i]-1);
			if(lookup.count({x[i]+1,y[i]-1})){
				adj[S].emplace_back(lookup[{x[i]+1,y[i]-1}]);
				adj[lookup[{x[i]+1,y[i]-1}]].emplace_back(S);
			} else lookup[{x[i]+1,y[i]-1}]=S;
			S++;
			adj.emplace_back();
			edges.emplace_back(i,lookup[{x[i]+2,y[i]}],x[i]+1,y[i]+1);
			if(lookup.count({x[i]+1,y[i]+1})){
				adj[S].emplace_back(lookup[{x[i]+1,y[i]+1}]);
				adj[lookup[{x[i]+1,y[i]+1}]].emplace_back(S);
			} else lookup[{x[i]+1,y[i]+1}]=S;
			adj[S].emplace_back(S-1);
			adj[S-1].emplace_back(S);
		}
		if(lookup.count({x[i],y[i]-2})){
			adjsepar[i].emplace_back(lookup[{x[i],y[i]-2}]);
			adjsepar[lookup[{x[i],y[i]-2}]].emplace_back(i);
			S++;
			adj.emplace_back();
			edges.emplace_back(i,lookup[{x[i],y[i]-2}],x[i]-1,y[i]-1);
			if(lookup.count({x[i]-1,y[i]-1})){
				adj[S].emplace_back(lookup[{x[i]-1,y[i]-1}]);
				adj[lookup[{x[i]-1,y[i]-1}]].emplace_back(S);
			} else lookup[{x[i]-1,y[i]-1}]=S;
			S++;
			adj.emplace_back();
			edges.emplace_back(i,lookup[{x[i],y[i]-2}],x[i]+1,y[i]-1);
			if(lookup.count({x[i]+1,y[i]-1})){
				adj[S].emplace_back(lookup[{x[i]+1,y[i]-1}]);
				adj[lookup[{x[i]+1,y[i]-1}]].emplace_back(S);
			} else lookup[{x[i]+1,y[i]-1}]=S;
			adj[S].emplace_back(S-1);
			adj[S-1].emplace_back(S);
		}
	}
	vector<bool> visited(n);
	int vis = 0;
	function<void(int)> dfshelp = [&](int x){
		if(visited[x])return;
		visited[x]=true;
		vis++;
		for(int&i:adjsepar[x])dfshelp(i);
	};
	dfshelp(0);
	vector<int> colour(S+1,-1);
	bool works = true;
	function<void(int,int)> dfs = [&](int x,int col){
		if(colour[x]!=-1){
			if(colour[x]!=col)works=false;
			return;
		}
		colour[x]=col;
		for(int&i:adj[x])dfs(i,col^1);
	};
	for(int i=1;i<=S;i++)if(colour[i]==-1)dfs(i,0);
	if(!works or vis!=n)return 0;
	for(int i=1;i<=S;i++){
		if(colour[i]==0)continue;
		auto [c,d,e,f] = edges[i];
		u.emplace_back(c);
		v.emplace_back(d);
		a.emplace_back(e);
		b.emplace_back(f);
	}
	build(u,v,a,b);
	return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 315 ms 53332 KB Output is correct
10 Correct 14 ms 5768 KB Output is correct
11 Correct 85 ms 28852 KB Output is correct
12 Correct 18 ms 8332 KB Output is correct
13 Correct 56 ms 21620 KB Output is correct
14 Correct 1 ms 860 KB Output is correct
15 Correct 3 ms 1116 KB Output is correct
16 Correct 248 ms 50804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 315 ms 53332 KB Output is correct
10 Correct 14 ms 5768 KB Output is correct
11 Correct 85 ms 28852 KB Output is correct
12 Correct 18 ms 8332 KB Output is correct
13 Correct 56 ms 21620 KB Output is correct
14 Correct 1 ms 860 KB Output is correct
15 Correct 3 ms 1116 KB Output is correct
16 Correct 248 ms 50804 KB Output is correct
17 Incorrect 0 ms 344 KB Tree @(3, 3) appears more than once: for edges on positions 1 and 2
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 315 ms 53332 KB Output is correct
10 Correct 14 ms 5768 KB Output is correct
11 Correct 85 ms 28852 KB Output is correct
12 Correct 18 ms 8332 KB Output is correct
13 Correct 56 ms 21620 KB Output is correct
14 Correct 1 ms 860 KB Output is correct
15 Correct 3 ms 1116 KB Output is correct
16 Correct 248 ms 50804 KB Output is correct
17 Incorrect 0 ms 344 KB Tree @(3, 3) appears more than once: for edges on positions 1 and 2
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 315 ms 53332 KB Output is correct
10 Correct 14 ms 5768 KB Output is correct
11 Correct 85 ms 28852 KB Output is correct
12 Correct 18 ms 8332 KB Output is correct
13 Correct 56 ms 21620 KB Output is correct
14 Correct 1 ms 860 KB Output is correct
15 Correct 3 ms 1116 KB Output is correct
16 Correct 248 ms 50804 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 687 ms 108376 KB Output is correct
21 Correct 612 ms 93524 KB Output is correct
22 Correct 731 ms 92488 KB Output is correct
23 Correct 500 ms 89944 KB Output is correct
24 Correct 134 ms 22344 KB Output is correct
25 Correct 648 ms 85584 KB Output is correct
26 Correct 648 ms 85780 KB Output is correct
27 Correct 727 ms 96252 KB Output is correct
28 Correct 700 ms 96336 KB Output is correct
29 Correct 699 ms 96340 KB Output is correct
30 Correct 683 ms 95968 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 29 ms 6596 KB Output is correct
33 Correct 61 ms 11868 KB Output is correct
34 Correct 613 ms 105172 KB Output is correct
35 Correct 18 ms 3976 KB Output is correct
36 Correct 109 ms 18876 KB Output is correct
37 Correct 252 ms 37372 KB Output is correct
38 Correct 234 ms 35768 KB Output is correct
39 Correct 304 ms 47712 KB Output is correct
40 Correct 460 ms 60652 KB Output is correct
41 Correct 652 ms 72784 KB Output is correct
42 Correct 716 ms 86116 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 4 ms 1116 KB Output is correct
55 Correct 4 ms 1372 KB Output is correct
56 Correct 268 ms 47148 KB Output is correct
57 Correct 476 ms 71888 KB Output is correct
58 Correct 464 ms 70488 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 0 ms 348 KB Output is correct
62 Correct 661 ms 104628 KB Output is correct
63 Correct 656 ms 105568 KB Output is correct
64 Correct 663 ms 106576 KB Output is correct
65 Correct 6 ms 1780 KB Output is correct
66 Correct 13 ms 3348 KB Output is correct
67 Correct 274 ms 45360 KB Output is correct
68 Correct 494 ms 70904 KB Output is correct
69 Correct 693 ms 91340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 315 ms 53332 KB Output is correct
10 Correct 14 ms 5768 KB Output is correct
11 Correct 85 ms 28852 KB Output is correct
12 Correct 18 ms 8332 KB Output is correct
13 Correct 56 ms 21620 KB Output is correct
14 Correct 1 ms 860 KB Output is correct
15 Correct 3 ms 1116 KB Output is correct
16 Correct 248 ms 50804 KB Output is correct
17 Correct 622 ms 108740 KB Output is correct
18 Correct 669 ms 103252 KB Output is correct
19 Correct 720 ms 108628 KB Output is correct
20 Correct 909 ms 99156 KB Output is correct
21 Correct 694 ms 88684 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 75 ms 14860 KB Output is correct
24 Correct 43 ms 8572 KB Output is correct
25 Correct 184 ms 29540 KB Output is correct
26 Correct 396 ms 52576 KB Output is correct
27 Correct 346 ms 48736 KB Output is correct
28 Correct 481 ms 63056 KB Output is correct
29 Correct 611 ms 74372 KB Output is correct
30 Correct 717 ms 86352 KB Output is correct
31 Correct 849 ms 96600 KB Output is correct
32 Correct 843 ms 103872 KB Output is correct
33 Correct 624 ms 107348 KB Output is correct
34 Correct 8 ms 2324 KB Output is correct
35 Correct 17 ms 3960 KB Output is correct
36 Correct 291 ms 49468 KB Output is correct
37 Correct 519 ms 75092 KB Output is correct
38 Correct 837 ms 98208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 315 ms 53332 KB Output is correct
10 Correct 14 ms 5768 KB Output is correct
11 Correct 85 ms 28852 KB Output is correct
12 Correct 18 ms 8332 KB Output is correct
13 Correct 56 ms 21620 KB Output is correct
14 Correct 1 ms 860 KB Output is correct
15 Correct 3 ms 1116 KB Output is correct
16 Correct 248 ms 50804 KB Output is correct
17 Incorrect 0 ms 344 KB Tree @(3, 3) appears more than once: for edges on positions 1 and 2
18 Halted 0 ms 0 KB -