이 제출은 이전 버전의 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};
const vector<int> dy = {0, 0, 1, -1};
const vector<int> dxx = {1, 1, 1, -1, -1, -1, 0, 0};
const vector<int> dyy = {0, 1, -1, 0, 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});
while (!pq.empty()) {
int d, x, y;
tie(d, x, y) = pq.top(); pq.pop();
if (d > dist[x][y]) continue;
if (d % (n + 1) < n && d % (n + 1) > 0) {
for (int k = 0; k < 8; k++) {
int nx = x + dxx[k], ny = y + dyy[k];
if (nx < 0 || nx >= r || ny < 0 || ny >= c) continue;
if (d + 1 < dist[nx][ny]) {
dist[nx][ny] = d + 1;
pq.push({dist[nx][ny], nx, ny});
}
}
}
if (d % (n + 1) == 0) {
for (int k = 0; k < 4; k++) {
int nx = x + dx[k], ny = y + dy[k];
if (nx < 0 || nx >= r || ny < 0 || ny >= c) continue;
if (d + 1 < dist[nx][ny]) {
dist[nx][ny] = d + 1;
pq.push({dist[nx][ny], nx, ny});
}
}
}
for (int k = 0; k < 4; k++) {
int nx = x + dx[k], ny = y + dy[k];
if (nx < 0 || nx >= r || ny < 0 || ny >= c || grid[nx][ny] == '#') continue;
if ((d + n) / (n + 1) * (n + 1) < dist[nx][ny]) {
dist[nx][ny] = (d + n) / (n + 1) * (n + 1);
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:60:3: note: in expansion of macro 'debug'
60 | 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... |