Submission #209337

#TimeUsernameProblemLanguageResultExecution timeMemory
209337papaEmacs (COCI20_emacs)C++14
50 / 50
6 ms504 KiB
#include <bits/stdc++.h> using namespace std; //za svaku komponentu vidimo da li je u obliku pravougaonika //koristimo bfs da nadjemo 'temena' pravougaonika int n,m; int mat[105][105]; int vis[105][105]; int cnt = 0; int sol; int por[] = {1,-1,0,0}; int pok[] = {0,0,1,-1}; void bfs(int sr,int sk) { queue<pair<int,int > > q; q.push({sr,sk}); vis[sr][sk] = 1; cnt = 0; int rmaks = sr; int rmin = sr; int kmaks = sk; int kmin = sk; while(!q.empty()) { pair<int,int> p =q.front(); q.pop(); cnt++; int tr = p.first; rmaks = max(rmaks,tr); rmin = min(rmin,tr); int tk = p.second; kmaks = max(kmaks,tk); kmin = min(kmin,tk); for(int i=0;i<4;i++) { int nr = tr+por[i]; int nk = tk+pok[i]; if(nr>=1 && nr<=n && nk>=1 && nk<=m && !vis[nr][nk] && mat[nr][nk]) { vis[nr][nk] = 1; q.push({nr,nk}); } } } if((rmaks-rmin+1)*(kmaks-kmin+1) == cnt) sol++; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cerr.tie(0); cin >> n >> m; for(int i=1;i<=n;i++) { string s; cin >> s; for(int j=0;j<m;j++) { if(s[j]=='*') mat[i][j+1] = 1; else mat[i][j+1] = 0; } } sol = 0; for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { if(!vis[i][j] && mat[i][j]) { bfs(i,j); } } } cout << sol; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...