// Code by author: NAKCUAEBE
#pragma GCC optimize("O2")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
/*#####DEFINE#####*/
#define faster ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//#deinfe int long long
#define ii pair<int,int>
#define fi first
#define se second
#define vi vector<int>
#define vii vector<ii>
#define ll long long
#define fou(i,j,n) for(int i=(j);i<=(n);i++)
#define fod(i,j,n) for(int i=(j);i>=(n);i--)
#define MASK(i) (1LL<<(i))
#define BIT(x,i) (((x)>>(i))&1)
#define mod 1000000007
#define maxn 1005
using namespace std;
/*######FILE#####*/
#define NAKIUPTTM ""
void file()
{
freopen(NAKIUPTTM".INP","r",stdin);
freopen(NAKIUPTTM".OUT","w",stdout);
}
/*#####VARIABLE#####*/
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};
int n,m;
char c;
int t[maxn][maxn];
bool dd[maxn][maxn];
int ans=0;
/*#####Starting code#####*/
void dfs(int x,int y,int parx,int pary,int now)
{
dd[x][y]=1;
//cout<<x<<' '<<y<<'\n';
for(int i=0;i<4;i++)
{
int nx=x+dx[i];
int ny=y+dy[i];
if(nx<=0||nx>n||ny<=0||ny>m||(ny==pary&&nx==parx)||dd[nx][ny]||t[nx][ny]!=now)continue;
dfs(nx,ny,x,y,now);
}
}
void solve()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
cin>>c;
if(c=='*')t[i][j]=2;
if(c=='T')t[i][j]=1;
}
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)if(!dd[i][j]&&t[i][j]!=2)dfs(i,j,-1,-1,t[i][j]),ans++;
cout<<ans;
}
int main()
{
faster;
//file();
ll t=1;
//cin>>t;
while(t--)
{
solve();
}
return 0;
}
Compilation message
zoo.cpp: In function 'void solve()':
zoo.cpp:71:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
71 | for(int i=1;i<=n;i++)
| ^~~
zoo.cpp:73:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
73 | cout<<ans;
| ^~~~
zoo.cpp: In function 'void file()':
zoo.cpp:32:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
32 | freopen(NAKIUPTTM".INP","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
zoo.cpp:33:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | freopen(NAKIUPTTM".OUT","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |