Submission #1212440

#TimeUsernameProblemLanguageResultExecution timeMemory
1212440i_love_springTracks in the Snow (BOI13_tracks)C++20
2.19 / 100
718 ms794988 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ar array
const int inf = 1e9;
const int rc[]{0,0,1,-1};
const int cc[]{1,-1,0,0};
const int N = 4004;
char a[N][N];
bool vis[N][N];
int ans = 0, n, m;
void dfs(int x,int y, char c) {
  vis[x][y] = 1;
  for (int i = 0; i < 4;i++) {
    int nx = x + rc[i],ny = y + cc[i];
    if (nx >=0 && nx < n && ny >= 0 && ny < m && !vis[nx][ny] && a[nx][ny] == c) {
      dfs(nx,ny,c);
    } 
  }
} 
void solve() {
  cin >> n >> m;
  int ok = 0, ok1 = 0;
  for (int i = 0; i < n;i++) {
    for (int j = 0; j < m;j++) {
      cin >> a[i][j];
      if (a[i][j] == 'R') ok = 1;
      if (a[i][j] == 'F') ok1 = 1;
    }
  }
  ans = ok + ok1;
  char c = a[0][0];
  dfs(0,0,c);
  for (int i = 0; i < n;i++) {
    for (int j = 0; j < m;j++) if (c == a[i][j] && !vis[i][j]){
      ans++;
    }
  }
  cout << ans;
  
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int t = 1;
//  cin >> t;
  while (t--) {
    solve();
    cout << "\n";
  }
  return 0;
} 
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...