| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 48708 | Extazy | Tracks in the Snow (BOI13_tracks) | C++17 | 2102 ms | 603512 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
const int N = 4007;
const pair < int, int > D[4] = {
  make_pair(1,0),
  make_pair(-1,0),
  make_pair(0,1),
  make_pair(0,-1)
};
int n,m;
char a[N][N];
bool used[N][N];
int ans;
void clear_used() {
  int i,j;
  for(i=1;i<=n;i++) {
    for(j=1;j<=m;j++) {
      used[i][j]=false;
    }
  }
}
void dfs(int r, int c, char ch) {
  a[r][c]='#';
  used[r][c]=true;
  int i,p,t;
  for(i=0;i<4;i++) {
    p=r+D[i].first;
    t=c+D[i].second;
    if(p>=1 && p<=n && t>=1 && t<=m) if(!used[p][t]) if(a[p][t]==ch || a[p][t]=='#') dfs(p,t,ch);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int i,j;
  char curr;
  scanf("%d %d", &n, &m);
  for(i=1;i<=n;i++) {
    scanf("%s", a[i]+1);
  }
  curr=a[1][1];
  bool found=true;
  while(found) {
    found=false;
    for(i=1;!found && i<=n;i++) {
      for(j=1;!found && j<=m;j++) {
        if(a[i][j]==curr) {
          clear_used();
          dfs(i,j,a[i][j]);
          ++ans;
          if(curr=='R') curr='F';
          else curr='R';
          
          found=true;
        }
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
