답안 #1047987

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1047987 2024-08-07T19:31:36 Z Unforgettablepl 분수 공원 (IOI21_parks) C++17
30 / 100
731 ms 108076 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]})){
			if(lookup.count({x[i]+2,y[i]+2}) and lookup.count({x[i],y[i]+2}))goto next;
			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);
		}
		next:
		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);
			if(x[i]==2){
				u.emplace_back(i);
				v.emplace_back(lookup[{x[i],y[i]-2}]);
				a.emplace_back(x[i]-1);
				b.emplace_back(y[i]-1);
				continue;
			} else if(x[i]==6){
				u.emplace_back(i);
				v.emplace_back(lookup[{x[i],y[i]-2}]);
				a.emplace_back(x[i]+1);
				b.emplace_back(y[i]-1);
				continue;
			}
			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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 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 440 KB Output is correct
9 Correct 116 ms 24904 KB Output is correct
10 Correct 7 ms 3180 KB Output is correct
11 Correct 49 ms 13768 KB Output is correct
12 Correct 10 ms 4188 KB Output is correct
13 Correct 28 ms 9116 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 110 ms 22348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 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 440 KB Output is correct
9 Correct 116 ms 24904 KB Output is correct
10 Correct 7 ms 3180 KB Output is correct
11 Correct 49 ms 13768 KB Output is correct
12 Correct 10 ms 4188 KB Output is correct
13 Correct 28 ms 9116 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 110 ms 22348 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 436 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 535 ms 75588 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 2 ms 896 KB Output is correct
26 Correct 3 ms 1372 KB Output is correct
27 Correct 5 ms 1372 KB Output is correct
28 Correct 147 ms 29548 KB Output is correct
29 Correct 260 ms 46680 KB Output is correct
30 Correct 379 ms 66400 KB Output is correct
31 Correct 491 ms 75104 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 344 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 2 ms 1116 KB Output is correct
44 Correct 5 ms 1372 KB Output is correct
45 Correct 231 ms 42132 KB Output is correct
46 Correct 389 ms 59232 KB Output is correct
47 Correct 410 ms 58468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 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 440 KB Output is correct
9 Correct 116 ms 24904 KB Output is correct
10 Correct 7 ms 3180 KB Output is correct
11 Correct 49 ms 13768 KB Output is correct
12 Correct 10 ms 4188 KB Output is correct
13 Correct 28 ms 9116 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 110 ms 22348 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 436 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 535 ms 75588 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 2 ms 896 KB Output is correct
26 Correct 3 ms 1372 KB Output is correct
27 Correct 5 ms 1372 KB Output is correct
28 Correct 147 ms 29548 KB Output is correct
29 Correct 260 ms 46680 KB Output is correct
30 Correct 379 ms 66400 KB Output is correct
31 Correct 491 ms 75104 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 344 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 2 ms 1116 KB Output is correct
44 Correct 5 ms 1372 KB Output is correct
45 Correct 231 ms 42132 KB Output is correct
46 Correct 389 ms 59232 KB Output is correct
47 Correct 410 ms 58468 KB Output is correct
48 Correct 1 ms 344 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 432 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 0 ms 348 KB Output is correct
55 Correct 476 ms 64468 KB Output is correct
56 Correct 0 ms 344 KB Output is correct
57 Correct 2 ms 856 KB Output is correct
58 Correct 9 ms 2228 KB Output is correct
59 Correct 11 ms 2908 KB Output is correct
60 Correct 181 ms 32884 KB Output is correct
61 Correct 246 ms 43376 KB Output is correct
62 Correct 389 ms 52336 KB Output is correct
63 Correct 468 ms 69216 KB Output is correct
64 Correct 1 ms 344 KB Output is correct
65 Correct 0 ms 432 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 281 ms 46816 KB Output is correct
68 Correct 262 ms 47012 KB Output is correct
69 Correct 269 ms 48292 KB Output is correct
70 Correct 5 ms 1628 KB Output is correct
71 Correct 10 ms 2672 KB Output is correct
72 Correct 219 ms 34184 KB Output is correct
73 Correct 344 ms 56128 KB Output is correct
74 Correct 518 ms 68956 KB Output is correct
75 Correct 534 ms 70132 KB Output is correct
76 Correct 273 ms 50596 KB Output is correct
77 Correct 6 ms 1880 KB Output is correct
78 Correct 11 ms 2968 KB Output is correct
79 Correct 225 ms 36720 KB Output is correct
80 Correct 363 ms 57452 KB Output is correct
81 Correct 543 ms 73308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 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 440 KB Output is correct
9 Correct 116 ms 24904 KB Output is correct
10 Correct 7 ms 3180 KB Output is correct
11 Correct 49 ms 13768 KB Output is correct
12 Correct 10 ms 4188 KB Output is correct
13 Correct 28 ms 9116 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 110 ms 22348 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 731 ms 108076 KB Output is correct
21 Correct 633 ms 94048 KB Output is correct
22 Incorrect 717 ms 92244 KB Tree @(7, 99997) appears more than once: for edges on positions 0 and 178152
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 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 440 KB Output is correct
9 Correct 116 ms 24904 KB Output is correct
10 Correct 7 ms 3180 KB Output is correct
11 Correct 49 ms 13768 KB Output is correct
12 Correct 10 ms 4188 KB Output is correct
13 Correct 28 ms 9116 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 110 ms 22348 KB Output is correct
17 Correct 544 ms 94156 KB Output is correct
18 Correct 598 ms 96784 KB Output is correct
19 Incorrect 702 ms 102788 KB Tree @(7, 49999) appears more than once: for edges on positions 0 and 33713
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 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 440 KB Output is correct
9 Correct 116 ms 24904 KB Output is correct
10 Correct 7 ms 3180 KB Output is correct
11 Correct 49 ms 13768 KB Output is correct
12 Correct 10 ms 4188 KB Output is correct
13 Correct 28 ms 9116 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 110 ms 22348 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 436 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 535 ms 75588 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 2 ms 896 KB Output is correct
26 Correct 3 ms 1372 KB Output is correct
27 Correct 5 ms 1372 KB Output is correct
28 Correct 147 ms 29548 KB Output is correct
29 Correct 260 ms 46680 KB Output is correct
30 Correct 379 ms 66400 KB Output is correct
31 Correct 491 ms 75104 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 344 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 2 ms 1116 KB Output is correct
44 Correct 5 ms 1372 KB Output is correct
45 Correct 231 ms 42132 KB Output is correct
46 Correct 389 ms 59232 KB Output is correct
47 Correct 410 ms 58468 KB Output is correct
48 Correct 1 ms 344 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 432 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 0 ms 348 KB Output is correct
55 Correct 476 ms 64468 KB Output is correct
56 Correct 0 ms 344 KB Output is correct
57 Correct 2 ms 856 KB Output is correct
58 Correct 9 ms 2228 KB Output is correct
59 Correct 11 ms 2908 KB Output is correct
60 Correct 181 ms 32884 KB Output is correct
61 Correct 246 ms 43376 KB Output is correct
62 Correct 389 ms 52336 KB Output is correct
63 Correct 468 ms 69216 KB Output is correct
64 Correct 1 ms 344 KB Output is correct
65 Correct 0 ms 432 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 281 ms 46816 KB Output is correct
68 Correct 262 ms 47012 KB Output is correct
69 Correct 269 ms 48292 KB Output is correct
70 Correct 5 ms 1628 KB Output is correct
71 Correct 10 ms 2672 KB Output is correct
72 Correct 219 ms 34184 KB Output is correct
73 Correct 344 ms 56128 KB Output is correct
74 Correct 518 ms 68956 KB Output is correct
75 Correct 534 ms 70132 KB Output is correct
76 Correct 273 ms 50596 KB Output is correct
77 Correct 6 ms 1880 KB Output is correct
78 Correct 11 ms 2968 KB Output is correct
79 Correct 225 ms 36720 KB Output is correct
80 Correct 363 ms 57452 KB Output is correct
81 Correct 543 ms 73308 KB Output is correct
82 Correct 0 ms 348 KB Output is correct
83 Correct 0 ms 348 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 731 ms 108076 KB Output is correct
86 Correct 633 ms 94048 KB Output is correct
87 Incorrect 717 ms 92244 KB Tree @(7, 99997) appears more than once: for edges on positions 0 and 178152
88 Halted 0 ms 0 KB -