# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
766909 | tamyte | Tracks in the Snow (BOI13_tracks) | C++14 | 534 ms | 76184 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
void setIO(string name = "")
{
cin.tie(0)->sync_with_stdio(0); // see /general/fast-io
if (name.size())
{
freopen((name + ".in").c_str(), "r", stdin); // see /general/input-output
freopen((name + ".out").c_str(), "w", stdout);
}
}
int n, m;
bool ok(int i, int j) {
return min(i, j) >= 0 && i < n && j < m;
}
void solve() {
cin >> n >> m;
vector<vector<char>> arr(n, vector<char>(m));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
cin >> arr[i][j];
}
}
vector<vector<bool>> vis(n, vector<bool>(m));
int cnt = 1;
deque<pair<int, int>> dq;
dq.push_front({0, 0});
vector<int> dx = {0, 1, 0, -1}, dy = {1, 0, -1, 0};
char now = arr[0][0];
while (dq.size()) {
auto c = dq.front(); dq.pop_front();
if (arr[c.first][c.second] != now) {
now = arr[c.first][c.second];
cnt++;
}
for (int i = 0; i < 4; ++i) {
int ii = dy[i] + c.first;
int jj = dx[i] + c.second;
if (!ok(ii, jj) || vis[ii][jj] || arr[ii][jj] == '.') continue;
vis[ii][jj] = true;
if (arr[ii][jj] != now) {
dq.push_back({ii, jj});
} else {
dq.push_front({ii, jj});
}
}
}
cout << cnt << "\n";
}
int main () {
setIO();
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |