# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
282405 | AMO5 | Emacs (COCI20_emacs) | C++17 | 1 ms | 384 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>
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 |
---|---|---|---|---|
Fetching results... |