이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include "templates/debug.h"
#else
#define debug(...) 0
#endif
const vector<int> dx = {1, -1, 0, 0, 1, 1, -1, -1};
const vector<int> dy = {0, 0, 1, -1, -1, 1, -1, 1};
const int INF = 0x3f3f3f3f;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int r, c, n; cin >> r >> c >> n;
int sr, sc, gr, gc; cin >> sr >> sc >> gr >> gc;
sr--; sc--; gr--; gc--;
vector<string> grid(r);
for (int i = 0; i < r; i++) cin >> grid[i];
vector< vector<int> > dist(r, vector<int>(c, INF)); dist[sr][sc] = 0;
priority_queue< tuple<int, int, int>, vector< tuple<int, int, int> >, greater<> > pq; pq.push({0, sr, sc});
deque< pair<int, int> > q;
while (!q.empty() || !pq.empty()) {
int d, x, y;
if (q.empty()) tie(d, x, y) = pq.top(), pq.pop();
else {
tie(x, y) = q.front(); q.pop_front();
d = dist[x][y];
}
if (d > dist[x][y]) continue;
for (int k = 0; k < 8; k++) {
int nx = x + dx[k], ny = y + dy[k];
if (nx < 0 || nx >= r || ny < 0 || ny >= c) continue;
if (0 < d % (n + 1) && d % (n + 1) < n && d + 1 < dist[nx][ny]) {
dist[nx][ny] = d + 1;
q.push_back({nx, ny});
}
if (k >= 4) continue;
if (d % (n + 1) == 0 && d + 1 < dist[nx][ny]) {
dist[nx][ny] = d + 1;
q.push_back({nx, ny});
}
if (d % (n + 1) == n && d + 2 < dist[nx][ny]) {
dist[nx][ny] = d + 2;
pq.push({dist[nx][ny], nx, ny});
}
if (grid[nx][ny] == '.' && (d + n) / (n + 1) * (n + 1) < dist[nx][ny]) {
dist[nx][ny] = (d + n) / (n + 1) * (n + 1);
if (d % (n + 1) == 0) q.push_back({nx, ny});
else pq.push({dist[nx][ny], nx, ny});
}
}
}
debug(dist);
cout << (dist[gr][gc] + n) / (n + 1) << '\n';
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int main()':
Main.cpp:7:20: warning: statement has no effect [-Wunused-value]
7 | #define debug(...) 0
| ^
Main.cpp:58:3: note: in expansion of macro 'debug'
58 | debug(dist);
| ^~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |