Submission #105132

# Submission time Handle Problem Language Result Execution time Memory
105132 2019-04-10T16:29:02 Z leonarda Konj (COCI19_konj) C++14
70 / 70
116 ms 12628 KB
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int, int> pi;
int n, tx, ty;
vector<pi> m[300 + 5][300 + 5];
bool memo[300 + 5][300 + 5];
queue<int> qx, qy;
char crtez[300 + 5][300 + 5];
int minix = 0x3f3f3f3f, maksx = 0, miniy = 0x3f3f3f3f, maksy = 0;
vector<pi> v1, v2;

void crtaj(int x, int y) {
	for(int i = 0; i < m[x][y].size(); ++i) {
		int u = m[x][y][i].first; 
		int v = m[x][y][i].second;
		
		minix = min(minix, u);
		maksx = max(maksx, u);
		miniy = min(miniy, v);
		maksy = max(maksy, v);
		
		if(u == x) {
			for(int j = min(y, v); j <= max(y, v); ++j)
				crtez[x][j] = '#';
		} else if(y == v) {
			for(int j = min(u, x); j <= max(u, x); ++j) {
				crtez[j][y] = '#';
			}
		}
	}
	return;
}

int main ()
{
	ios::sync_with_stdio(0);
	
	cin >> n;
	for(int i = 0; i < n; ++i) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		v1.pb(mp(a, b)); v2.pb(mp(c, d));
		m[a][b].pb(mp(c, d));
		m[c][d].pb(mp(a, b));
	}
	
	cin >> tx >> ty;
	
	for(int i = 0; i < n; ++i) {
		if(v1[i].first == v2[i].first) {
			if(tx == v1[i].first and ty >= min(v1[i].second, v2[i].second) and ty <= max(v1[i].second, v2[i].second)) {
				qx.push(v1[i].first); qy.push(v1[i].second);
				qx.push(v2[i].first); qy.push(v2[i].second);
			}
		} else if(v1[i].second == v2[i].second) {
			if(ty == v1[i].second and tx >= min(v1[i].first, v2[i].first) and tx <= max(v1[i].first, v2[i].first)) {
				qx.push(v1[i].first); qy.push(v1[i].second);
				qx.push(v2[i].first); qy.push(v2[i].second);
			}
		}
	}
	
	while(!qx.empty()) {
		int x = qx.front();
		int y = qy.front();
		qx.pop(); qy.pop();
		if(memo[x][y] == 1) continue;
		else {
			for(int i = 0; i < m[x][y].size(); ++i) {
				qx.push(m[x][y][i].first);
				qy.push(m[x][y][i].second);
			}
			memo[x][y] = 1;	
		}
	}
		
	for(int i = 0; i <= 304; ++i) {
		for(int j = 0; j <= 304; ++j) {
			if(memo[i][j]) {
				crtaj(i, j);
				maksx = max(maksx, i);
				maksy = max(maksy, j);
				minix = min(minix, i);
				miniy = min(miniy, j);
			}
		}
	}
		
	for(int i = maksy; i >= miniy; --i) {
		if(i != maksy) cout << endl;
		for(int j = minix; j <= maksx; ++j) {
			if(crtez[j][i] == '#') cout << crtez[j][i];
			else cout << '.';
		}
	}

return 0;
}

Compilation message

konj.cpp: In function 'void crtaj(int, int)':
konj.cpp:15:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < m[x][y].size(); ++i) {
                 ~~^~~~~~~~~~~~~~~~
konj.cpp: In function 'int main()':
konj.cpp:71:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int i = 0; i < m[x][y].size(); ++i) {
                   ~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2560 KB Output is correct
2 Correct 5 ms 2560 KB Output is correct
3 Correct 116 ms 12628 KB Output is correct
4 Correct 5 ms 2560 KB Output is correct
5 Correct 5 ms 2560 KB Output is correct
6 Correct 6 ms 2560 KB Output is correct
7 Correct 5 ms 2608 KB Output is correct
8 Correct 5 ms 2560 KB Output is correct
9 Correct 5 ms 2560 KB Output is correct
10 Correct 5 ms 2560 KB Output is correct