# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
46595 | Bruteforceman | Tracks in the Snow (BOI13_tracks) | C++11 | 949 ms | 316896 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
char a[4001][4001];
int d[4001][4001];
const int dx[] = {0, 0, -1, 1};
const int dy[] = {-1, 1, 0, 0};
int N, M;
typedef pair <int, int> pii;
const int inf = 1e9;
bool inside(int x, int y) {
return (0 <= x && x < N) && (0 <= y && y < M);
}
int main(int argc, char const *argv[])
{
scanf("%d %d", &N, &M);
for(int i = 0; i < N; i++) {
scanf("%s", a[i]);
}
for(int i = 0; i < N; i++) {
for(int j = 0; j < M; j++) {
d[i][j] = inf;
}
}
deque <pii> Q;
Q.push_front(pii(N - 1, M - 1));
d[N - 1][M - 1] = 0;
while(!Q.empty()) {
pii c = Q.front();
Q.pop_front();
for(int i = 0; i < 4; i++) {
int p = c.first + dx[i];
int q = c.second + dy[i];
if(inside(p, q) && a[p][q] != '.') {
int w = (a[c.first][c.second] != a[p][q]);
if(d[p][q] > w + d[c.first][c.second]) {
d[p][q] = w + d[c.first][c.second];
if(w) Q.push_back(pii(p, q));
else Q.push_front(pii(p, q));
}
}
}
}
int ans = 0;
for(int i = 0; i < N; i++) {
for(int j = 0; j < M; j++) {
if(a[i][j] != '.') {
ans = max(ans, d[i][j]);
}
}
}
printf("%d\n", ans + 1);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |