답안 #770338

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
770338 2023-07-01T05:46:17 Z SanguineChameleon Sky Walking (IOI19_walk) C++17
24 / 100
3481 ms 917736 KB
#include "walk.h"
#include <bits/stdc++.h>
using namespace std;

const long long inf = 1e18L + 20;
const int maxN = 2e5 + 20;
const int max_nodes = maxN * 12;
int X[maxN];
int Y[maxN * 2];
int H[maxN * 2];
int L[maxN];
int R[maxN];
pair<int, int> orderY[maxN * 2];
vector<int> qadd[maxN];
vector<int> qrem[maxN];
vector<int> row[maxN];
vector<int> col[maxN * 2];
long long dist[max_nodes];
vector<pair<int, int>> adj[max_nodes];
map<pair<int, int>, int> points;
int node_cnt;

int get_id(int i, int j) {
	auto it = points.find(make_pair(i, j));
	if (it == points.end()) {
		return points[make_pair(i, j)] = ++node_cnt;
	}
	else {
		return it->second;
	}
}

void add_edge(int i1, int j1, int i2, int j2) {
	int u = get_id(i1, j1);
	int v = get_id(i2, j2);
	int w = abs(X[i1] - X[i2]) + abs(Y[j1] - Y[j2]);
	adj[u].emplace_back(v, w);
	adj[v].emplace_back(u, w);
}

long long min_distance(vector<int> _X, vector<int> _H, vector<int> _L, vector<int> _R, vector<int> _Y, int _S, int _T) {
	int N = _X.size();
	int M = _L.size();
	for (int i = 1; i <= N; i++) {
		X[i] = _X[i - 1];
	}
	for (int i = 1; i <= M; i++) {
		orderY[i] = make_pair(_Y[i - 1], i);
	}
	for (int i = M + 1; i <= M + N; i++) {
		orderY[i] = make_pair(_H[i - M - 1], i);
	}
	sort(orderY + 1, orderY + N + M + 1);
	for (int i = 1; i <= N + M; i++) {
		Y[i] = orderY[i].first;
		H[orderY[i].second] = i;
	}
	for (int i = 1; i <= M; i++) {
		L[i] = _L[i - 1] + 1;
		R[i] = _R[i - 1] + 1;
		qadd[L[i]].push_back(i);
		qrem[R[i]].push_back(i);
	}
	set<int> walks;
	for (int i = 1; i <= N; i++) {
		col[i].push_back(0);
		col[i].push_back(H[M + i]);
		for (auto id: qadd[i]) {
			walks.insert(H[id]);
		}
		auto it = walks.upper_bound(H[M + i]);
		while (it != walks.begin()) {
			it--;
			col[i].push_back(*it);
			row[*it].push_back(i);
		}
		for (auto id: qrem[i]) {
			walks.erase(H[id]);
		}
	}
	for (int i = 1; i <= N; i++) {
		sort(col[i].begin(), col[i].end());
		for (int j = 0; j < (int)col[i].size() - 1; j++) {
			add_edge(i, col[i][j], i, col[i][j + 1]);
		}
	}
	for (int i = 1; i <= M; i++) {
		sort(row[H[i]].begin(), row[H[i]].end());
		for (int j = 0; j < (int)row[H[i]].size() - 1; j++) {
			add_edge(row[H[i]][j], H[i], row[H[i]][j + 1], H[i]);
		}
	}
	int S = get_id(_S + 1, 0);
	int T = get_id(_T + 1, 0);
	for (int i = 1; i <= node_cnt; i++) {
		dist[i] = inf;
	}
	dist[S] = 0;
	priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> Q;
	Q.emplace(0, S);
	while (!Q.empty()) {
		int u = Q.top().second;
		if (Q.top().first != dist[u]) {
			Q.pop();
			continue;
		}
		Q.pop();
		for (auto e: adj[u]) {
			int v = e.first;
			int w = e.second;
			if (dist[u] + w < dist[v]) {
				dist[v] = dist[u] + w;
				Q.emplace(dist[v], v);
			}
		}
	}
	if (dist[T] == inf) {
		return -1;
	}
	else {
		return dist[T];
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 80096 KB Output is correct
2 Correct 38 ms 80112 KB Output is correct
3 Correct 37 ms 80204 KB Output is correct
4 Correct 37 ms 80212 KB Output is correct
5 Correct 42 ms 80268 KB Output is correct
6 Correct 43 ms 80200 KB Output is correct
7 Correct 37 ms 80200 KB Output is correct
8 Correct 36 ms 80160 KB Output is correct
9 Correct 37 ms 80092 KB Output is correct
10 Correct 38 ms 80252 KB Output is correct
11 Correct 37 ms 80108 KB Output is correct
12 Correct 37 ms 80200 KB Output is correct
13 Correct 36 ms 80204 KB Output is correct
14 Correct 38 ms 80152 KB Output is correct
15 Correct 35 ms 80080 KB Output is correct
16 Correct 36 ms 80156 KB Output is correct
17 Correct 42 ms 80332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 80148 KB Output is correct
2 Correct 35 ms 80164 KB Output is correct
3 Correct 1408 ms 202712 KB Output is correct
4 Correct 1380 ms 230352 KB Output is correct
5 Correct 1008 ms 213596 KB Output is correct
6 Correct 911 ms 201176 KB Output is correct
7 Correct 941 ms 213836 KB Output is correct
8 Correct 1939 ms 237036 KB Output is correct
9 Correct 1095 ms 210544 KB Output is correct
10 Correct 1866 ms 281300 KB Output is correct
11 Correct 714 ms 158120 KB Output is correct
12 Correct 529 ms 154940 KB Output is correct
13 Correct 1586 ms 261988 KB Output is correct
14 Correct 462 ms 150220 KB Output is correct
15 Correct 549 ms 153480 KB Output is correct
16 Correct 493 ms 152532 KB Output is correct
17 Correct 507 ms 150236 KB Output is correct
18 Correct 510 ms 151032 KB Output is correct
19 Correct 53 ms 83544 KB Output is correct
20 Correct 194 ms 114576 KB Output is correct
21 Correct 403 ms 146276 KB Output is correct
22 Correct 498 ms 154088 KB Output is correct
23 Correct 669 ms 161968 KB Output is correct
24 Correct 504 ms 152636 KB Output is correct
25 Correct 497 ms 150360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 175 ms 104184 KB Output is correct
2 Runtime error 3481 ms 917736 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 175 ms 104184 KB Output is correct
2 Runtime error 3481 ms 917736 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 80096 KB Output is correct
2 Correct 38 ms 80112 KB Output is correct
3 Correct 37 ms 80204 KB Output is correct
4 Correct 37 ms 80212 KB Output is correct
5 Correct 42 ms 80268 KB Output is correct
6 Correct 43 ms 80200 KB Output is correct
7 Correct 37 ms 80200 KB Output is correct
8 Correct 36 ms 80160 KB Output is correct
9 Correct 37 ms 80092 KB Output is correct
10 Correct 38 ms 80252 KB Output is correct
11 Correct 37 ms 80108 KB Output is correct
12 Correct 37 ms 80200 KB Output is correct
13 Correct 36 ms 80204 KB Output is correct
14 Correct 38 ms 80152 KB Output is correct
15 Correct 35 ms 80080 KB Output is correct
16 Correct 36 ms 80156 KB Output is correct
17 Correct 42 ms 80332 KB Output is correct
18 Correct 42 ms 80148 KB Output is correct
19 Correct 35 ms 80164 KB Output is correct
20 Correct 1408 ms 202712 KB Output is correct
21 Correct 1380 ms 230352 KB Output is correct
22 Correct 1008 ms 213596 KB Output is correct
23 Correct 911 ms 201176 KB Output is correct
24 Correct 941 ms 213836 KB Output is correct
25 Correct 1939 ms 237036 KB Output is correct
26 Correct 1095 ms 210544 KB Output is correct
27 Correct 1866 ms 281300 KB Output is correct
28 Correct 714 ms 158120 KB Output is correct
29 Correct 529 ms 154940 KB Output is correct
30 Correct 1586 ms 261988 KB Output is correct
31 Correct 462 ms 150220 KB Output is correct
32 Correct 549 ms 153480 KB Output is correct
33 Correct 493 ms 152532 KB Output is correct
34 Correct 507 ms 150236 KB Output is correct
35 Correct 510 ms 151032 KB Output is correct
36 Correct 53 ms 83544 KB Output is correct
37 Correct 194 ms 114576 KB Output is correct
38 Correct 403 ms 146276 KB Output is correct
39 Correct 498 ms 154088 KB Output is correct
40 Correct 669 ms 161968 KB Output is correct
41 Correct 504 ms 152636 KB Output is correct
42 Correct 497 ms 150360 KB Output is correct
43 Correct 175 ms 104184 KB Output is correct
44 Runtime error 3481 ms 917736 KB Execution killed with signal 11
45 Halted 0 ms 0 KB -