이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define endl "\n"
#define ll long long
#define mp make_pair
#define ins insert
#define lb lower_bound
#define pb push_back
#define ub upper_bound
#define lll __int128
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
int main() {
ios_base::sync_with_stdio(0); cin.tie(NULL);
int n, m;
cin >> n >> m;
char a[n + 5][m + 5];
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= m; ++j)
cin >> a[i][j];
deque<pair<int, pair<int, int>>> bfs;
bfs.push_back(mp(0, mp(1, 1)));
bool vis[n + 5][m + 5];
int res = 0;
memset(vis, 0, sizeof(vis));
vector<pair<int, int>> nxt = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
function<bool(int, int)> check = [&] (int x, int y) -> int {
return x <= n && x >= 1 && y >= 1 && y <= m;
};
while(bfs.size()) {
int d = bfs.front().fi, x = bfs.front().se.fi, y = bfs.front().se.se;
bfs.pop_front();
if(vis[x][y])
continue;
vis[x][y] = 1;
res = max(res, d);
// cout << x << " " << y << " " << d << endl;
for(auto p : nxt) {
if(check(x + p.fi, y + p.se) && !vis[x + p.fi][y + p.se] && a[x + p.fi][y + p.se] != '.') {
if(a[x + p.fi][y + p.se] == a[x][y])
bfs.push_front(mp(d, mp(x + p.fi, y + p.se)));
else
bfs.pb(mp(d + 1, mp(x + p.fi, y + p.se)));
}
}
}
cout << res + 1 << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |