# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1053898 | catsarecool5530 | Tracks in the Snow (BOI13_tracks) | C++17 | 372 ms | 124128 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define endl "\n"
const ll MOD = 1e9 + 7;
void setIO() { freopen("input.in", "r", stdin); }
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
int dirx[4]{0, 1, 0, -1};
int diry[4]{1, 0, -1, 0};
int n, m;
vector<string> snow;
bool inside(int x, int y) {
return (x > -1 && x < n && y > -1 && y < m && snow[x][y] != '.');
}
void solve() {
cin >> n >> m;
snow = vector<string> (n);
for (string& i : snow) cin >> i;
int ans = 0;
vector<vector<int>> depth(n, vector<int>(m));
depth[0][0] = 1;
deque<array<int, 2>> de;
de.push_back({0, 0});
while (!de.empty()) {
auto [x, y] = de.front();
de.pop_front();
ans = max(depth[x][y], ans);
for (int i = 0; i < 4; i++) {
if (!inside(x + dirx[i], y + diry[i])) continue;
if (depth[x + dirx[i]][y + diry[i]] != 0) continue;
if (snow[x][y] == snow[x + dirx[i]][y + diry[i]]) {
depth[x + dirx[i]][y + diry[i]] = depth[x][y];
de.push_front({x + dirx[i], y + diry[i]});
} else {
depth[x + dirx[i]][y + diry[i]] = depth[x][y] + 1;
de.push_back({x + dirx[i], y + diry[i]});
}
}
}
cout << ans << endl;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
//setIO();
ll t = 1; //cin >> t;
while (t--) {
solve();
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |