| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1291218 | jim_x | Tracks in the Snow (BOI13_tracks) | C++17 | 613 ms | 110684 KiB |
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <numeric>
#include <queue>
#include <stack>
#include <iomanip>
using namespace std;
void baseIO(string s = ""){
ios_base::sync_with_stdio(0);
cin.tie(0);
if (s.size()){
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
}
vector<pair<int, int>> change = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
int main() {
baseIO();
int h, w;
cin >> h >> w;
char grid[h][w];
for (int i = 0; i < h; i++){
for (int j = 0; j < w; j++) cin >> grid[i][j];
}
vector<vector<int>> dist(h, vector<int>(w, 0));
dist[0][0] = 1;
deque<pair<int, int>> q;
q.push_front({0, 0});
while (!q.empty()) {
pair<int, int> c = q.front();
q.pop_front();
for (auto chg : change){
int nx = c.first + chg.first, ny = c.second + chg.second;
if (0 <= nx && nx < h && 0 <= ny && ny < w && grid[nx][ny] != '.' && dist[nx][ny] == 0){
if (grid[c.first][c.second] == grid[nx][ny]){
dist[nx][ny] = dist[c.first][c.second];
q.push_front({nx, ny});
}else{
dist[nx][ny] = dist[c.first][c.second] + 1;
q.push_back({nx, ny});
}
}
}
}
int ans = 0;
for (int i = 0; i < h; i++){
for (int j = 0; j < w; j++){
if (dist[i][j] != 1e9) ans = max(ans, dist[i][j]);
}
}
cout << ans << endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
