Submission #373272

# Submission time Handle Problem Language Result Execution time Memory
373272 2021-03-04T02:10:18 Z sam571128 Selotejp (COCI20_selotejp) C++14
0 / 110
1 ms 364 KB
#include <bits/stdc++.h>

#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

const int N = 1e3+5;
int grid[N][15], visited[N][15];
int n,m, ans = 0;

void dfs(int x, int y){
	visited[x][y] = 1;
	bool ver = 0, hor = 0;
	for(int dx : {-1,0,1}){
		for(int dy : {-1,0,1}){
			if(abs(dx)==abs(dy)) continue;
			if(x+dx<0||x+dx>=n||y+dy<0||y+dy>=m) continue;
			if(!grid[x+dx][y+dy]) continue;
			if(dx) ver = 1;
			if(dy) hor = 1;
			if(visited[x+dx][y+dy]) continue;
			dfs(x+dx,y+dy);
		}
	}
	if(ver&&hor){
		ans++;
	}
}

signed main(){
	fastio
	cin >> n >> m;
	for(int i = 0;i < n;i++){
		for(int j = 0;j < m;j++){
			char c;
			cin >> c;
			if(c=='#') grid[i][j] = 1;
		}
	}
	for(int i = 0;i < n;i++){
		for(int j = 0;j < m;j++){
			if(!visited[i][j]&&grid[i][j]) ans++, dfs(i,j);
		}
	}
	cout << ans << "\n";
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -