#include <bits/stdc++.h>
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
using namespace std;
struct E {
int to, w;
};
const int K = 505, H = 105, N = K * H,
C = 805, Z = 402, INF = 1e9, M = C * C * 3;
vector<pair<int, int>> holes[K];
vector<E> g[M], g2[N];
int d[M], s[K], d2[N];
int getId(int x, int y, int z) {
return x * C * 3 + y * 3 + z;
}
void addEdge(int a, int b, int c) {
g[a].push_back({b, c});
g[b].push_back({a, c});
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int m, k, sx, sy, ex, ey;
cin >> k >> m >> sx >> sy >> ex >> ey;
for (int x = 0; x < C; x++) {
for (int y = 0; y < C; y++) {
if (m == 1) {
addEdge(getId(x, y, 0), getId(x, y, 1), 0);
addEdge(getId(x, y, 1), getId(x, y, 2), 0);
}
if (x + 1 < C) {
addEdge(getId(x, y, 0), getId(x + 1, y, 1), 1);
addEdge(getId(x, y, 2), getId(x + 1, y, 2), 1);
}
if (y + 1 < C) {
addEdge(getId(x, y, 0), getId(x, y + 1, 2), 1);
addEdge(getId(x, y, 1), getId(x, y + 1, 1), 1);
}
if (x + m < C) {
addEdge(getId(x, y, 1), getId(x + m, y, 0), 1);
}
if (y + m < C) {
addEdge(getId(x, y, 2), getId(x, y + m, 0), 1);
}
}
}
fill(d, d + M, -1);
int start = getId(Z, Z, 0);
d[start] = 0;
deque<int> q;
q.push_back(start);
while (!q.empty()) {
int node = q.front();
q.pop_front();
for (E e : g[node]) {
if (d[e.to] == -1) {
d[e.to] = d[node] + e.w;
if (e.w)
q.push_back(e.to);
else
q.push_front(e.to);
}
}
}
// cout << d[getId(Z + 1, Z + 1, 0)];
// return 0;
holes[k].push_back({sx, sy});
holes[0].push_back({ex, ey});
for (int i = k - 1; i > 0; i--) {
int h;
cin >> h;
while (h--) {
int x, y;
cin >> x >> y;
holes[i].push_back({x, y});
}
}
for (int i = 0; i < k; i++) {
s[i + 1] = s[i] + holes[i].size();
}
for (int i = 1; i <= k; i++) {
for (int x = 0; x < holes[i].size(); x++) {
for (int y = 0; y < holes[i - 1].size(); y++) {
int dist = d[getId(holes[i - 1][y].first - holes[i][x].first + Z,
holes[i - 1][y].second - holes[i][x].second + Z,
0)];
// cout << x + s[i] << " " << y + s[i - 1] << "\n";
g2[x + s[i]].push_back({y + s[i - 1], dist});
}
}
}
priority_queue<pair<int, int>,
vector<pair<int, int>>,
greater<pair<int, int>>> pq;
fill(d2, d2 + N, INF);
d2[s[k]] = 0;
pq.push({0, s[k]});
while (!pq.empty()) {
auto p = pq.top();
pq.pop();
if (p.first > d2[p.second])
continue;
int node = p.second;
for (E e : g2[node]) {
if (d2[e.to] > d2[node] + e.w) {
d2[e.to] = d2[node] + e.w;
pq.push({d2[e.to], e.to});
}
}
}
cout << d2[0] << "\n";
return 0;
}
Compilation message
obelisk.cpp: In function 'int main()':
obelisk.cpp:102:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int x = 0; x < holes[i].size(); x++) {
~~^~~~~~~~~~~~~~~~~
obelisk.cpp:103:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int y = 0; y < holes[i - 1].size(); y++) {
~~^~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
799 ms |
207264 KB |
Output is correct |
2 |
Correct |
802 ms |
207196 KB |
Output is correct |
3 |
Correct |
792 ms |
207148 KB |
Output is correct |
4 |
Correct |
790 ms |
207300 KB |
Output is correct |
5 |
Correct |
802 ms |
207128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
713 ms |
147148 KB |
Output is correct |
2 |
Correct |
688 ms |
147284 KB |
Output is correct |
3 |
Correct |
784 ms |
147844 KB |
Output is correct |
4 |
Correct |
639 ms |
147104 KB |
Output is correct |
5 |
Correct |
777 ms |
147732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
727 ms |
160648 KB |
Output is correct |
2 |
Correct |
787 ms |
164464 KB |
Output is correct |
3 |
Correct |
792 ms |
162296 KB |
Output is correct |
4 |
Correct |
940 ms |
164496 KB |
Output is correct |
5 |
Correct |
767 ms |
163960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
818 ms |
262144 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |