답안 #100604

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
100604 2019-03-12T19:05:59 Z kraljlavova1 Konj (COCI19_konj) C++11
70 / 70
85 ms 10232 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
const int MAX = 3e2 + 10;
int n, idx;
int tx, ty;
int a, b, c, d;
int xmx, ymx, xmn = MAX, ymn = MAX;
int bio[MAX][MAX];
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
char P[MAX][MAX];
vector<int> duz[MAX][MAX];
void dfs(int x, int y){
	bio[x][y] = 1;
	for(int i = 0;i < 4; i++){
		int nx = x + dx[i];
		int ny = y + dy[i];
		if(nx < 0 || nx >= MAX) continue;
		if(ny < 0 || ny >= MAX) continue;
		if(bio[nx][ny]) continue;
		for(int p : duz[x][y]){
			for(int q : duz[nx][ny]){
				if(p == q){
					dfs(nx, ny);
					goto G;
				}
			}
		}
		G:;
	}
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	cin >> n;
	while(n--){
		cin >> a >> b >> c >> d;
		if(a > c) swap(a, c);
		if(b > d) swap(b, d);
		for(int i = a;i <= c; i++){
			for(int j = b;j <= d; j++){
				duz[i][j].push_back(idx);
			}
		}idx++;
	}
	cin >> tx >> ty;
	dfs(tx, ty);
	for(int i = 0;i < MAX; i++){
		for(int j = 0;j < MAX; j++){
			if(!bio[i][j]) continue;
			xmx = max(xmx, i);
			xmn = min(xmn, i);
			ymx = max(ymx, j);
			ymn = min(ymn, j);
		}
	}
	for(int i = 0;i < MAX; i++){
		for(int j = 0;j < MAX; j++){
			if(bio[i][j]) P[i][j] = '#';
			else P[i][j] = '.';
		}
	}
	for(int j = ymx;j >= ymn; j--){
		for(int i = xmn;i <= xmx; i++){
			cout << P[i][j];
		}
		cout << "\n";
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2816 KB Output is correct
2 Correct 4 ms 2816 KB Output is correct
3 Correct 85 ms 10232 KB Output is correct
4 Correct 4 ms 2816 KB Output is correct
5 Correct 5 ms 2816 KB Output is correct
6 Correct 4 ms 2816 KB Output is correct
7 Correct 4 ms 2816 KB Output is correct
8 Correct 4 ms 2816 KB Output is correct
9 Correct 4 ms 2688 KB Output is correct
10 Correct 5 ms 2816 KB Output is correct