Submission #247533

# Submission time Handle Problem Language Result Execution time Memory
247533 2020-07-11T15:01:54 Z mieszko11b Building Skyscrapers (CEOI19_skyscrapers) C++14
0 / 100
3500 ms 156108 KB
#include <bits/stdc++.h>

using namespace std;

using ii = pair<int, int>;

#define X first
#define Y second

int n, t, cnt;
map<ii, int> M;
ii cor[1000007];
int skynum[150007];
int component[1000007];
bool engaged[1000007];
vector<int> incomp[1000007];
vector<int> G4[1000007], G8[1000007];
bool vis[1000007];
int ecnt;

void add_point(int x, int y) {
	ii p = {x, y};
	if(!M.count(p)) {
		M[p] = ++cnt;
		cor[cnt] = p;
		component[cnt] = cnt;
		incomp[cnt].push_back(cnt);
	}
}

bool check(int i) {
	bool eng[3][3];
	int comp[3][3];
	for(int w : G8[i]) {
		int x = cor[w].X - cor[i].X + 1;
		int y = cor[w].Y - cor[i].Y + 1;
		eng[x][y] = engaged[w];
		comp[x][y] = component[w];
	}
	
	if(!eng[0][1] && !eng[1][2] && comp[0][1] == comp[1][2] && eng[0][2]
		&& (eng[0][0] || eng[1][0] || eng[2][0] || eng[2][1] || eng[2][2]))
			return false;
	if(!eng[1][2] && !eng[2][1] && comp[1][2] == comp[2][1] && eng[2][2]
		&& (eng[2][0] || eng[1][0] || eng[0][0] || eng[0][1] || eng[0][2]))
			return false;
	if(!eng[2][1] && !eng[1][0] && comp[2][1] == comp[1][0] && eng[2][0]
		&& (eng[0][0] || eng[0][1] || eng[0][2] || eng[1][2] || eng[2][2]))
			return false;
	if(!eng[1][0] && !eng[0][1] && comp[1][0] == comp[1][0] && eng[0][0]
		&& (eng[0][2] || eng[1][2] || eng[2][2] || eng[2][1] || eng[2][0]))
			return false;
	if(!eng[0][1] && !eng[2][1] && comp[0][1] == comp[2][1]
		&& (eng[0][0] || eng[1][0] || eng[2][0]) && (eng[0][2] || eng[1][2] || eng[2][2]))
			return false;
	if(!eng[1][0] && !eng[1][2] && comp[1][0] == comp[1][2]
		&& (eng[0][0] || eng[0][1] || eng[0][2]) && (eng[2][0] || eng[2][1] || eng[2][2]))
			return false;
			
	return true;
}

void merge(int a, int b) {
	if(a == b)
		return ;
		
	if(incomp[b].size() > incomp[a].size())
		swap(a, b);
		
	for(int x : incomp[b]) {
		incomp[a].push_back(x);
		component[x] = a;
	}
	incomp[b].clear();
}

void erase(int w) {
	engaged[w] = 0;
	for(int u : G4[w])
		if(!engaged[u])
			merge(component[w], component[u]);
}

void dfs(int w) {
	if(vis[w])
		return ;
	vis[w] = 1;
	ecnt++;
		
	for(int u : G8[w])
		if(engaged[u])
			dfs(u);
}

int main() {
	scanf("%d%d", &n, &t);
	
	for(int i = 1 ; i <= n ; i++) {
		int r, c;
		scanf("%d%d", &r, &c);
		for(int x = -1 ; x <= 1 ; x++)
			for(int y = -1 ; y <= 1 ; y++)
				add_point(r + x, c + y);
		engaged[M[{r, c}]] = 1;
		skynum[i] = M[{r, c}];
	}
	
	for(int i = 1 ; i <= cnt ; i++) {
		int x = cor[i].X;
		int y = cor[i].Y;
		
		for(int xo = -1 ; xo <= 1 ; xo++) {
			for(int yo = -1 ; yo <= 1 ; yo++) {
				ii p2 = {x + xo, y + yo};
				if(M.count(p2) == 0)
					continue;
				int num = M[p2];
				
				if(xo || yo)
					G8[i].push_back(num);
				if((xo || yo) && !(xo && yo)) {
					G4[i].push_back(num);
					if(!engaged[i] && !engaged[num])
						merge(component[i], component[num]);
				}
			}
		}
	}
	
	dfs(skynum[1]);
	if(ecnt != n) {
		printf("NO\n");
		return 0;
	}
	
	printf("YES\n");
	vector<int> res;
	for(int i = 0 ; i < n ; i++) {
		for(int j = n ; j >= 1 ; j--) {
			if(engaged[skynum[j]] && check(skynum[j])) {
				erase(skynum[j]);
				res.push_back(j);
				break;
			}
		}
	}
	
	reverse(res.begin(), res.end());
	for(int x :  res)
		printf("%d\n", x);
	
	return 0;
}

Compilation message

skyscrapers.cpp: In function 'int main()':
skyscrapers.cpp:96:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &t);
  ~~~~~^~~~~~~~~~~~~~~~
skyscrapers.cpp:100:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &r, &c);
   ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 44 ms 70724 KB ans=YES N=1
2 Correct 46 ms 70780 KB ans=YES N=4
3 Correct 47 ms 70776 KB ans=NO N=4
4 Correct 53 ms 70828 KB ans=YES N=5
5 Correct 46 ms 70776 KB ans=YES N=9
6 Correct 45 ms 70784 KB ans=YES N=5
7 Correct 44 ms 70784 KB ans=NO N=9
8 Correct 52 ms 70816 KB ans=NO N=10
9 Correct 45 ms 70784 KB ans=YES N=10
10 Incorrect 43 ms 70784 KB Added cell 8 (2,0) not reachable from infinity
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 44 ms 70724 KB ans=YES N=1
2 Correct 46 ms 70780 KB ans=YES N=4
3 Correct 47 ms 70776 KB ans=NO N=4
4 Correct 53 ms 70828 KB ans=YES N=5
5 Correct 46 ms 70776 KB ans=YES N=9
6 Correct 45 ms 70784 KB ans=YES N=5
7 Correct 44 ms 70784 KB ans=NO N=9
8 Correct 52 ms 70816 KB ans=NO N=10
9 Correct 45 ms 70784 KB ans=YES N=10
10 Incorrect 43 ms 70784 KB Added cell 8 (2,0) not reachable from infinity
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 44 ms 70724 KB ans=YES N=1
2 Correct 46 ms 70780 KB ans=YES N=4
3 Correct 47 ms 70776 KB ans=NO N=4
4 Correct 53 ms 70828 KB ans=YES N=5
5 Correct 46 ms 70776 KB ans=YES N=9
6 Correct 45 ms 70784 KB ans=YES N=5
7 Correct 44 ms 70784 KB ans=NO N=9
8 Correct 52 ms 70816 KB ans=NO N=10
9 Correct 45 ms 70784 KB ans=YES N=10
10 Incorrect 43 ms 70784 KB Added cell 8 (2,0) not reachable from infinity
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 82 ms 74104 KB ans=NO N=1934
2 Correct 60 ms 71928 KB ans=NO N=1965
3 Incorrect 75 ms 71288 KB Added cell 1824 (370,234) not reachable from infinity
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 44 ms 70724 KB ans=YES N=1
2 Correct 46 ms 70780 KB ans=YES N=4
3 Correct 47 ms 70776 KB ans=NO N=4
4 Correct 53 ms 70828 KB ans=YES N=5
5 Correct 46 ms 70776 KB ans=YES N=9
6 Correct 45 ms 70784 KB ans=YES N=5
7 Correct 44 ms 70784 KB ans=NO N=9
8 Correct 52 ms 70816 KB ans=NO N=10
9 Correct 45 ms 70784 KB ans=YES N=10
10 Incorrect 43 ms 70784 KB Added cell 8 (2,0) not reachable from infinity
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 591 ms 92596 KB ans=NO N=66151
2 Correct 1761 ms 156108 KB ans=NO N=64333
3 Execution timed out 3574 ms 87404 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 82 ms 74104 KB ans=NO N=1934
2 Correct 60 ms 71928 KB ans=NO N=1965
3 Incorrect 75 ms 71288 KB Added cell 1824 (370,234) not reachable from infinity
4 Halted 0 ms 0 KB -