이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
#define all(x) x.begin(), x.end()
#define L(i, b, e) for (int i = b; i < e; ++i)
#define R(i, b, e) for (int i = b; i >= e; --i)
#define pb emplace_back
#define vi vector<int>
#define sz(x) ((int) x.size())
const int N = 4e3 + 7, Mx = 1e9 + 9;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
int n, m;
string s[N];
bool vis[N][N];
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
L(i, 0, n){
cin >> s[i];
}
auto in = [&](int x, int y){
return (x >= 0 && y >= 0 && x < n && y < m);
};
int ans = 1;
char lst = s[0][0];
deque<pair<int, int>> dq;
dq.push_back({0, 0});
vis[0][0] = true;
while (!dq.empty()){
pair<int, int> t = dq.front();
dq.pop_front();
if (s[t.first][t.second] != lst){
lst = s[t.first][t.second];
++ans;
}
L(i, 0, 4){
int nx = t.first + dx[i], ny = t.second + dy[i];
if (in(nx, ny) && vis[nx][ny] == false && s[nx][ny] != '.'){
if (s[nx][ny] == s[t.first][t.second])dq.push_front({nx, ny});
else dq.push_back({nx, ny});
vis[nx][ny] = true;
}
}
}
cout << ans;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |