#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
typedef long double ld ;
#define FAST ios::sync_with_stdio(0), cin.tie(0),cout.tie(0)
#define pb push_back
#define pi pair<ll,ll>
#define pll pair<ll,ll>
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define firsst cout<<"First"<<endl;
#define seconnd cout<<"Second"<<endl;
#define tiie cout<<"Tie"<<endl;
#define fr(i,a,b) for(ll i = a;i < (ll)b;i++)
#define rfr(i,a,b) for(ll i = a;i > (ll)b;i--)
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define alll(x) ((x).begin()+1), (x).end()
#define MOD mod
#define endl '\n'
//#define uid(a, b) uniform_ll_distribution<ll>(a, b)(rng)
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 998244353 ;
void io(){ios::sync_with_stdio(false) ;cin.tie(NULL) ;
//freopen("tractor.in","r",stdin) ;freopen("tractor.out","w",stdout) ;
}
void dbg(vector<ll> tab){for(auto it : tab) cout<<it<<" ";cout<<endl;}
void dbgg(pi p){cout<<p.F<<" "<<p.S<<endl;}
void dbgpi(vector<pi> tab){for(auto it : tab) dbgg(it) ;}
template<class T> bool ckmax(T& a, const T& b){return a < b ? a = b, 1 : 0;}
template<class T> bool ckmin(T& a, const T& b){return a > b ? a = b, 1 : 0;}
template<class T> void add(T& a, const T& b){a = a + b ; if(a>mod) a-= mod ;}
void nop(){cout<<-1<<endl;return;}
const ll N = 4e3+5 , NAX = 1e6 +5 ;
char tab[N][N] ;
int vis[N][N] ;
int n , m ;
int di[] = {-1 , 0 , 1 , 0} ;
int dj[] = {0 , 1 , 0 , -1} ;
bool ok(int i , int j)
{
if(i<1 || i>n || j<1 || j>m) return false ;
return true ;
}
void dfs(int i , int j , char c)
{
if(vis[i][j]) return ;
vis[i][j] = 1 ;
for(int k = 0 ; k<4 ; k++){
int ii = di[k]+i ;
int jj = dj[k]+j ;
if(ok(ii,jj) && tab[ii][jj]==c){
dfs(ii,jj,c) ;
}
}
}
void solve()
{
cin>>n>>m ;
for(int i = 1 ; i<=n ; i++){
for(int j = 1 ; j<=m ; j++){
cin>>tab[i][j] ;
}
}
char c = tab[1][1] , ok = 0 , ans = 0 ;
if(c=='.'){
cout<<0<<endl;
return ;
}
for(int i = 1 ; i<=n ; i++){
for(int j = 1 ; j<=m ; j++){
if(c==tab[i][j] && !vis[i][j]){
ans++ ;
dfs(i , j , c) ;
}
if(tab[i][j]!=c && tab[i][j]!='.') ok = 1 ;
}
}
cout<<ans+ok<<endl;
}
int main()
{
io() ;
ll tt = 1 ;
// cin>>tt ;
while(tt--) solve() ;
return 0 ;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
5332 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
724 KB |
Output isn't correct |
4 |
Incorrect |
7 ms |
6100 KB |
Output isn't correct |
5 |
Incorrect |
3 ms |
2904 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
724 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
852 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
1108 KB |
Output isn't correct |
10 |
Incorrect |
3 ms |
2516 KB |
Output isn't correct |
11 |
Incorrect |
3 ms |
2644 KB |
Output isn't correct |
12 |
Incorrect |
4 ms |
3028 KB |
Output isn't correct |
13 |
Incorrect |
3 ms |
2916 KB |
Output isn't correct |
14 |
Incorrect |
3 ms |
2900 KB |
Output isn't correct |
15 |
Incorrect |
9 ms |
5332 KB |
Output isn't correct |
16 |
Incorrect |
10 ms |
5376 KB |
Output isn't correct |
17 |
Incorrect |
7 ms |
5244 KB |
Output isn't correct |
18 |
Incorrect |
7 ms |
5972 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
31008 KB |
Output isn't correct |
2 |
Incorrect |
36 ms |
15100 KB |
Output isn't correct |
3 |
Incorrect |
273 ms |
73768 KB |
Output isn't correct |
4 |
Incorrect |
70 ms |
32652 KB |
Output isn't correct |
5 |
Incorrect |
156 ms |
50864 KB |
Output isn't correct |
6 |
Incorrect |
473 ms |
160544 KB |
Output isn't correct |
7 |
Incorrect |
16 ms |
32468 KB |
Output isn't correct |
8 |
Incorrect |
15 ms |
30932 KB |
Output isn't correct |
9 |
Incorrect |
3 ms |
852 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
11 |
Incorrect |
18 ms |
31764 KB |
Output isn't correct |
12 |
Incorrect |
1 ms |
1492 KB |
Output isn't correct |
13 |
Incorrect |
37 ms |
15116 KB |
Output isn't correct |
14 |
Incorrect |
23 ms |
10444 KB |
Output isn't correct |
15 |
Incorrect |
24 ms |
13132 KB |
Output isn't correct |
16 |
Incorrect |
16 ms |
5828 KB |
Output isn't correct |
17 |
Incorrect |
88 ms |
29036 KB |
Output isn't correct |
18 |
Incorrect |
82 ms |
35916 KB |
Output isn't correct |
19 |
Incorrect |
69 ms |
32640 KB |
Output isn't correct |
20 |
Incorrect |
64 ms |
25680 KB |
Output isn't correct |
21 |
Incorrect |
163 ms |
52804 KB |
Output isn't correct |
22 |
Incorrect |
148 ms |
50768 KB |
Output isn't correct |
23 |
Incorrect |
159 ms |
43984 KB |
Output isn't correct |
24 |
Incorrect |
155 ms |
48124 KB |
Output isn't correct |
25 |
Incorrect |
292 ms |
94784 KB |
Output isn't correct |
26 |
Correct |
1134 ms |
848040 KB |
Output is correct |
27 |
Incorrect |
715 ms |
509784 KB |
Output isn't correct |
28 |
Incorrect |
495 ms |
160516 KB |
Output isn't correct |
29 |
Incorrect |
490 ms |
167048 KB |
Output isn't correct |
30 |
Incorrect |
402 ms |
158240 KB |
Output isn't correct |
31 |
Incorrect |
355 ms |
73608 KB |
Output isn't correct |
32 |
Incorrect |
222 ms |
75944 KB |
Output isn't correct |