hiho week 159 register

Ended

Participants:533

Verdict:Accepted
Score:100 / 100
Submitted:2017-07-22 10:11:40

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 + 10;
int a[maxn][maxn],vis[maxn][maxn],n,m;
int dx[] = {-1,0,1,0};
int dy[] = {0,1,0,-1};
int dfs(int x,int y)
{
  vis[x][y] = 1;
  int ans = 0;
  for( int i = 0; i < 4; i++ ){
    int nx = x + dx[i],ny = y + dy[i];
    if(nx < 1 || nx > n || ny < 1 || ny > m)ans++;
    else if(!vis[nx][ny]){
      if(a[nx][ny] == a[x][y])ans += dfs(nx,ny);
      else ans++;
    }
  }
  return ans;
}
int main()
{
  int x,y;
  while(~scanf("%d%d%d%d",&n,&m,&x,&y)){
    for( int i = 1; i <= n; i++ )
      for( int j = 1; j <= m; j++ )scanf("%d",&a[i][j]);
    printf("%d\n",dfs(x+1,y+1));
  }
  return 0;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX