제출 #1360867

#제출 시각아이디문제언어결과실행 시간메모리
1360867vjudge1ACM (COCI19_acm)C++20
0 / 50
0 ms580 KiB
#include <iostream>
#include <cstring>
using namespace std;

const int MAX = 1e5 + 10; // ?? N�M ?1e5 ???
int n, m;
// ???????????
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

char grid[205][205];   // ??
bool vis[205][205];    // ????
bool has_treasure;     // ???????????

// DFS ???????????
void dfs(int x, int y) {
	vis[x][y] = true;
	// ??????? 2~9??????????
	if (grid[x][y] > '1') {
		has_treasure = true;
	}
	
	// ??????
	for (int i = 0; i < 4; i++) {
		int tx = x + dx[i];
		int ty = y + dy[i];
		// ???? + ??? + ???/????0?
		if (tx >= 0 && tx < n && ty >= 0 && ty < m 
			&& !vis[tx][ty] && grid[tx][ty] != '0') {
			dfs(tx, ty);
		}
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> grid[i];
	}
	memset(vis, false, sizeof(vis));
	
	int total = 0;   // ????
	int treasure = 0;// ???????
	
	// ??????
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			// ????????/?? = ???
			if (!vis[i][j] && grid[i][j] != '0') {
				has_treasure = false;
				dfs(i, j);
				total++;              // ????+1
				if (has_treasure) {   // ?????
					treasure++;
				}
			}
		}
	}
	
	cout << total << " " << treasure ;

}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…