# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1135443 | neowami | Tracks in the Snow (BOI13_tracks) | C++20 | 631 ms | 119020 KiB |
#include <bits/stdc++.h> // NeOWami
using namespace std;
#define ft first
#define sc second
using pii = pair<int, int>;
const int N = 4005;
const int inf = 1e9;
int n, m, ans = 0;
char c[N][N];
int dist[N][N];
int Dx[] = {1, -1, 0, 0}, Dy[] = {0, 0, -1, 1};
bool ckmin(int &u, int v) {
if (u > v) return u = v, 1;
return 0;
}
signed main() {
cin.tie(NULL)->sync_with_stdio(false);
if(ifstream("Input.inp")) {
freopen("Input.inp", "r", stdin);
freopen("Output.out", "w", stdout);
}
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> c[i][j];
dist[i][j] = inf;
}
}
dist[1][1] = 1;
deque<pii> dq;
dq.push_back({1, 1});
while(!dq.empty()) {
int x = dq.back().ft, y = dq.back().sc;
dq.pop_back();
ans = max(ans, dist[x][y]);
for (int mov = 0; mov < 4; mov++) {
int tx = x + Dx[mov], ty = y + Dy[mov];
if (!tx || !ty || tx > n || ty > m || c[tx][ty] == '.') continue;
if (c[tx][ty] == c[x][y] && ckmin(dist[tx][ty], dist[x][y])) dq.push_back({tx, ty});
if (c[tx][ty] != c[x][y] && ckmin(dist[tx][ty], dist[x][y] + 1)) dq.push_front({tx, ty});
}
}
cout << ans;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |