# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
282405 |
2020-08-24T12:00:15 Z |
AMO5 |
Emacs (COCI20_emacs) |
C++17 |
|
1 ms |
384 KB |
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define MOD 1000000007
typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;
const ll INF=63;
const int mxn=200;
bool DEBUG=0;
const int dx[]={-1,0,1,0};
const int dy[]={0,-1,0,1};
string grid[mxn];
bool vis[mxn][mxn];
int n,m;
bool check(int x, int y){
return 0<=x&&x<n&&0<=y&&y<=m;
}
void bfs(int x, int y){
queue<ii>q;
q.emplace(x,y);
while(!q.empty()){
x=q.front().fi;
y=q.front().se;
q.pop();
if(vis[x][y])continue;
vis[x][y]=1;
for(int k=0; k<4; k++){
int X=x+dx[k];
int Y=y+dy[k];
if(check(X,Y)&&!vis[X][Y]&&grid[X][Y]=='*'){
q.emplace(X,Y);
}
}
}
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
//freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
cin>>n>>m;
for(int i=0; i<n; i++)cin>>grid[i];
int cnt=0;
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
if(!vis[i][j]&&grid[i][j]=='*'){
bfs(i,j);
cnt++;
}
}
}
cout<<cnt;
}
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |