# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
985035 | pannenkoek | Tracks in the Snow (BOI13_tracks) | C++14 | 707 ms | 179456 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define pb push_back
#define fi first
#define se second
using ll = long long;
using ld = long double;
using pii = pair<ll, ll>;
const int MAXN = 4e3 + 5;
int h, w, dist[MAXN][MAXN];
char field[MAXN][MAXN];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> h >> w;
fill(&dist[0][0], &dist[0][0] + MAXN * MAXN, -1);
fill(&field[0][0], &field[0][0] + MAXN * MAXN, '.');
rep(i, 0, h)
rep(j, 0, w)
cin >> field[i + 1][j + 1];
deque<pii> d{{{1, 1}}};
dist[1][1] = 1;
int res = 0;
while(!d.empty()){
auto [i, j] = d.front();
d.pop_front();
res = dist[i][j];
for(auto [di, dj]: vector<pii>{{1, 0}, {-1, 0}, {0, 1}, {0, -1}}){
if(field[i + di][j + dj] == '.') continue;
if(dist[i + di][j + dj] >= 0) continue;
bool same = field[i + di][j + dj] == field[i][j];
dist[i + di][j + dj] = dist[i][j] + !same;
if(same) d.push_front({i + di, j + dj});
else d.push_back({i + di, j + dj});
}
}
cout << res << "\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |