Submission #282405

#TimeUsernameProblemLanguageResultExecution timeMemory
282405AMO5Emacs (COCI20_emacs)C++17
50 / 50
1 ms384 KiB
#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 timeMemoryGrader output
Fetching results...