이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// Author: RufatM
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1e9+7
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define pb push_back
#define pii pair<ll,int>
#define all(a) a.begin(), a.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int MAXN = 4005;
char grid[MAXN][MAXN];
bool visited[MAXN][MAXN];
int h,w;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
void dfs(int x,int y,char c){
visited[x][y] = true;
for(int k=0;k<4;k++){
int nx = x + dx[k];
int ny = y + dy[k];
if(nx >= 0 and nx < h and ny >= 0 and ny < w and !visited[nx][ny] and grid[nx][ny] == c) {
dfs(nx, ny, c);
}
}
}
signed main(){
fastio;
int t=1;
//cin >> t;
while(t--){
cin >> h >> w;
for(int i=0;i<h;i++){
cin >> grid[i];
}
int comp = 0;
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
if(grid[i][j] != '.' and !visited[i][j]){
dfs(i,j,grid[i][j]);
comp++;
}
}
}
cout<< min(2,comp) << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |