이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl
const int maxn = 1010;
int n, m;
string g[maxn];
bool done[maxn][maxn];
int cc = 0;
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>n>>m;
for (int i=0; i<n; i++) {
cin>>g[i];
}
queue<pair<int,int>> qq;
qq.push({0,0});
while (qq.size()) {
int x = qq.front().first;
int y = qq.front().second;
qq.pop();
if (x<0 || y<0 || x>=n || y>=m) continue;
char c = g[x][y];
if (c=='*') continue;
if (done[x][y]) continue;
cc++;
// flood this char
// add other char to queue
queue<pair<int,int>> flood;
flood.push({x,y});
while (flood.size()) {
//marked as done when flooded
int x = flood.front().first;
int y = flood.front().second;
flood.pop();
if (x<0 || y<0 || x>=n || y>=m) continue;
if (g[x][y]=='*') continue;
if (done[x][y]) continue;
if (c == g[x][y]) {
done[x][y] = true;
flood.push({x-1,y});
flood.push({x+1,y});
flood.push({x,y-1});
flood.push({x,y+1});
} else if (g[x][y] != '*') {
qq.push({x,y});
}
}
}
out(cc);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |