Submission #1126398

#TimeUsernameProblemLanguageResultExecution timeMemory
1126398AgageldiTracks in the Snow (BOI13_tracks)C++20
0 / 100
2128 ms702852 KiB
/*
ID: agageld1
LANG: C++17
TASK:
*/
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define N 400005
#define ff first
#define ss second
#define pb push_back
#define sz(s) (int)s.size()
#define rep(c, a, b) for(c = a; c <= b; c++)

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  
ll n, m, ans = 0, vis[5000][5000];
char a[5000][5000];

void solve(int x,int y,char p) {
	if(x > n || y > m || x == 0 || y == 0 || a[x][y] == '.' || vis[x][y]==1) {
		return;
	}
	if(a[x][y]!='*' && p!=a[x][y]) {
		return;
	}
	a[x][y] = '*';
	vis[x][y] = 1;
	solve(x+1,y,p);
	solve(x,y-1,p);
	solve(x,y+1,p);
	solve(x-1,y,p);
	vis[x][y] = 0;
}

int main () {
	//freopen("txt.in","r",stdin);
	//freopen("txt.out","w",stdout);
	ios::sync_with_stdio(0);cin.tie(0);
	cin >> n >> m;
	for(int i= 1;i<=n;i++) {
		for(int j =1;j<=m;j++) {
			cin >> a[i][j];
		}
	}
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			if(a[i][j] == '*') continue;
			if(a[i][j] != '.') {
				solve(i,j,a[i][j]);
				ans++;
				continue;
			}
		}
	}
	cout << ans << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...