답안 #551476

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
551476 2022-04-20T19:42:14 Z 1ne 분수 공원 (IOI21_parks) C++17
5 / 100
3500 ms 132692 KB
#include "parks.h"
#include<bits/stdc++.h>
using namespace std;
struct edges{
	int x,y,x1,y1;
};
int construct_roads(std::vector<int> x, std::vector<int> y) {
	 map<pair<int,int>,bool>mp,got;
	 map<pair<int,int>,int>index,need;
	 int n = (int)x.size();
	 for (int i = 0;i<n;++i){
		 mp[{x[i],y[i]}] = true;
		 got[{x[i],y[i]}] = false;
		 index[{x[i],y[i]}] = i;
	 }
	 auto comp = [&](int a,int b,int c,int d){
		if (a<c){
			return (edges){a,b,c,d};
		}
		else if (c < a){
				return (edges){c,d,a,b};
		}
		else if ( b < d){
			return (edges){a,b,c,d};
		}
		return (edges){c,d,a,b};
	 };
	 vector<edges>ans;
	 vector<int>dx = {2,0,-2,0};
	 vector<int>dy = {0,2,0,-2};
	 function<void(int,int)> dfs = [&](int u,int v){
		 got[{u,v}] = true;
		 for (int i = 0;i<4;++i){
			 int xx = u + dx[i];
			 int yy = v + dy[i];
			 if (mp[{xx,yy}] && !got[{xx,yy}]){
				 ans.push_back(comp(u,v,xx,yy));
				 dfs(xx,yy);
			 }
		 }
	 };
	 bool ok = true;
	 dfs(x[0],y[0]);
	 for (int i = 0;i<n;++i){
		 if (!got[{x[i],y[i]}]){
			 ok=false;
			 break;
		 }
	 }
	 if (!ok){
		 return 0;
	 }
	 vector<int>u,v,a,b;
	 queue<edges>q;
	 for (int i = 0;i<(int)ans.size();++i){
		edges z = ans[i];
		if (z.x == z.x1){
			need[{z.x - 1,z.y + 1}]++;
			need[{z.x + 1,z.y+1}]++;
		}
		else{
			need[{z.x + 1,z.y + 1}]++;
			need[{z.x + 1,z.y - 1}]++;
		}
		q.push(z);
	 }
	 while(!q.empty()){
		auto z = q.front();
		q.pop();
		if (z.x == z.x1){
			if (need[{z.x - 1,z.y + 1}]<=2){
				need[{z.x - 1,z.y + 1}] = INT_MAX;
				need[{z.x + 1,z.y+1}]--;
				u.push_back(index[{z.x,z.y}]);
				v.push_back(index[{z.x1,z.y1}]);
				a.push_back(z.x - 1);
				b.push_back(z.y + 1);
			}
			else if (need[{z.x + 1,z.y+1}]<=2){
				need[{z.x - 1,z.y + 1}]--;
				need[{z.x + 1,z.y+1}] = INT_MAX;
				u.push_back(index[{z.x,z.y}]);
				v.push_back(index[{z.x1,z.y1}]);
				a.push_back(z.x + 1);
				b.push_back(z.y + 1);
			}
			else q.push(z);
		}
		else{
			if (need[{z.x + 1,z.y + 1}]<=2){
				need[{z.x + 1,z.y + 1}] = INT_MAX;
				need[{z.x + 1,z.y-1}]--;
				u.push_back(index[{z.x,z.y}]);
				v.push_back(index[{z.x1,z.y1}]);
				a.push_back(z.x + 1);
				b.push_back(z.y + 1);
			}
			else if (need[{z.x + 1,z.y - 1}]<=2){
				need[{z.x + 1,z.y + 1}]--;
				need[{z.x + 1,z.y - 1}] = INT_MAX;
				u.push_back(index[{z.x,z.y}]);
				v.push_back(index[{z.x1,z.y1}]);
				a.push_back(z.x + 1);
				b.push_back(z.y - 1);
			}
			else q.push(z);
		}
	 }
	 
	
	 build(u,v,a,b);
    return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 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 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 479 ms 65420 KB Output is correct
10 Correct 28 ms 6936 KB Output is correct
11 Correct 226 ms 35808 KB Output is correct
12 Correct 62 ms 10148 KB Output is correct
13 Correct 82 ms 17352 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 490 ms 60360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 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 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 479 ms 65420 KB Output is correct
10 Correct 28 ms 6936 KB Output is correct
11 Correct 226 ms 35808 KB Output is correct
12 Correct 62 ms 10148 KB Output is correct
13 Correct 82 ms 17352 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 490 ms 60360 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Execution timed out 3563 ms 103192 KB Time limit exceeded
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 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 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 479 ms 65420 KB Output is correct
10 Correct 28 ms 6936 KB Output is correct
11 Correct 226 ms 35808 KB Output is correct
12 Correct 62 ms 10148 KB Output is correct
13 Correct 82 ms 17352 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 490 ms 60360 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Execution timed out 3563 ms 103192 KB Time limit exceeded
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 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 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 479 ms 65420 KB Output is correct
10 Correct 28 ms 6936 KB Output is correct
11 Correct 226 ms 35808 KB Output is correct
12 Correct 62 ms 10148 KB Output is correct
13 Correct 82 ms 17352 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 490 ms 60360 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1027 ms 107568 KB Output is correct
21 Correct 1077 ms 104764 KB Output is correct
22 Correct 1049 ms 101908 KB Output is correct
23 Correct 981 ms 107344 KB Output is correct
24 Correct 491 ms 42700 KB Output is correct
25 Correct 462 ms 42708 KB Output is correct
26 Correct 453 ms 42628 KB Output is correct
27 Execution timed out 3569 ms 92144 KB Time limit exceeded
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 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 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 479 ms 65420 KB Output is correct
10 Correct 28 ms 6936 KB Output is correct
11 Correct 226 ms 35808 KB Output is correct
12 Correct 62 ms 10148 KB Output is correct
13 Correct 82 ms 17352 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 490 ms 60360 KB Output is correct
17 Correct 1142 ms 132692 KB Output is correct
18 Correct 1117 ms 122732 KB Output is correct
19 Execution timed out 3576 ms 102912 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 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 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 479 ms 65420 KB Output is correct
10 Correct 28 ms 6936 KB Output is correct
11 Correct 226 ms 35808 KB Output is correct
12 Correct 62 ms 10148 KB Output is correct
13 Correct 82 ms 17352 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 490 ms 60360 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Execution timed out 3563 ms 103192 KB Time limit exceeded
24 Halted 0 ms 0 KB -