# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
101604 | shenxy | Tracks in the Snow (BOI13_tracks) | C++11 | 1820 ms | 110604 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cstdio>
#include <algorithm>
#include <deque>
#include <cstring>
#include <utility>
using namespace std;
typedef pair<int, int> coord;
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
const int INF = 1000000000;
int main() {
int H, W, ans = 0;
scanf("%d %d", &H, &W);
char mygrid[H][W];
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
scanf(" %c", &mygrid[i][j]);
}
}
int visited[H][W];
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
visited[i][j] = INF;
}
}
visited[0][0] = 0;
deque<coord> bfsq;
bfsq.push_back(coord(0, 0));
while (!bfsq.empty()) {
coord k = bfsq.front();
bfsq.pop_front();
for (int i = 0; i < 4; i++) {
if (k.first + dx[i] >= 0 && k.first + dx[i] < H && k.second + dy[i] >= 0 && k.second + dy[i] < W) {
if (mygrid[k.first + dx[i]][k.second + dy[i]] == mygrid[k.first][k.second]) {
if (visited[k.first + dx[i]][k.second + dy[i]] == INF) {
visited[k.first + dx[i]][k.second + dy[i]] = visited[k.first][k.second];
bfsq.push_front(coord(k.first + dx[i], k.second + dy[i]));
}
} else if (mygrid[k.first + dx[i]][k.second + dy[i]] != '.') {
if (visited[k.first + dx[i]][k.second + dy[i]] == INF) {
visited[k.first + dx[i]][k.second + dy[i]] = visited[k.first][k.second] + 1;
bfsq.push_back(coord(k.first + dx[i], k.second + dy[i]));
ans = max(ans, visited[k.first + dx[i]][k.second + dy[i]]);
}
}
}
}
}
printf("%d", ans + 1);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |