Submission #236396

# Submission time Handle Problem Language Result Execution time Memory
236396 2020-06-01T19:46:38 Z bayemirov Building Skyscrapers (CEOI19_skyscrapers) C++17
0 / 100
124 ms 9836 KB
//bayemirov                                       
#include <bits/stdc++.h>
   
using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;

#define pb push_back
#define f first
#define s second

const int N = 2e5;
const int INF = 1e9;
const int dx[] = {0, 0, 1, -1, 1, -1, 1, -1}; 
const int dy[] = {1, -1, 0, 0, 1, -1, -1, 1};

vector<pair<int, int>> points;
map<int, map<int, int>> id;
bool was[N];
int n, t, d[N];

bool ok(int j) {
	return j > 0 && !was[j];
}

bool check1(int v = 0, int cnt = 1, bool res = 0) {
	was[v] = 1;
	if (cnt == n) return 1;
	for (int i = 0; i < 8; i++) {
		int new_x = points[v].f + dx[i];
		int new_y = points[v].s + dy[i];
		if (ok(id[new_x][new_y]))
			res |= check1(id[new_x][new_y], cnt + 1);
	}
	return res;
}

bool check(auto p) {
	for (int i = 0; i < 4; i++) {
		int new_x = p.f + dx[i];
		int new_y = p.s + dy[i];
		if (!ok(id[new_x][new_y]))
			return 1;
	}
	return 0;
}

bool check2() {
	for (auto p : points) {
		if (!check(p))
			return 0;
	}
	return 1;
}

void bfs() {
	queue<int> q;
	q.push(0);
	fill(d, d + n, INF);
	d[0] = 0;
	while (!q.empty()) {
		int v = q.front();
		q.pop();
		for (int i = 0; i < 8; i++) {
			int new_x = points[v].f + dx[i];
			int new_y = points[v].s + dy[i];
			int u = id[new_x][new_y];
			if (u > 0 && d[u] > d[v] + 1) {
				d[u] = d[v] + 1;
				q.push(u);
			}
		}
	}
}

vector<int> get(vector<int> res = {}) {
	int v = n - 1;
	while (v) {
		res.pb(v);
		int best = -1;
		for (int i = 0; i < 8; i++) {
			int new_x = points[v].f + dx[i];
			int new_y = points[v].s + dy[i];
			int u = id[new_x][new_y];
			if (u >= 0 && was[u] && d[u] < d[v]) 
				best = max(best, u);
		}
		v = best;
	}
	res.pb(0);
	reverse(res.begin(), res.end());
	return res;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	cin >> n >> t;
	for (int i = 0; i < n; i++) {
		int x, y;
		cin >> x >> y;
		points.pb({x, y});
		id[x][y] = i;
	}
	if (!(check1() & check2())) cout << "NO", exit(0);
	cout << "YES\n";     	
	bfs();
	auto ans = get();
	for (auto x : ans) cout << x + 1 << "\n";
	return 0;                                         	
}                    
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB ans=YES N=1
2 Incorrect 5 ms 512 KB Unexpected end of file - int32 expected
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB ans=YES N=1
2 Incorrect 5 ms 512 KB Unexpected end of file - int32 expected
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB ans=YES N=1
2 Incorrect 5 ms 512 KB Unexpected end of file - int32 expected
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 768 KB ans=NO N=1934
2 Correct 6 ms 512 KB ans=NO N=1965
3 Incorrect 7 ms 768 KB Contestant did not find solution
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB ans=YES N=1
2 Incorrect 5 ms 512 KB Unexpected end of file - int32 expected
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 124 ms 9836 KB ans=NO N=66151
2 Correct 66 ms 7536 KB ans=NO N=64333
3 Incorrect 115 ms 7664 KB Contestant did not find solution
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 768 KB ans=NO N=1934
2 Correct 6 ms 512 KB ans=NO N=1965
3 Incorrect 7 ms 768 KB Contestant did not find solution
4 Halted 0 ms 0 KB -