제출 #716804

#제출 시각아이디문제언어결과실행 시간메모리
716804TAhmed33Tracks in the Snow (BOI13_tracks)C++98
2.19 / 100
1587 ms31712 KiB
#include <bits/stdc++.h>
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, -1, 0, 1};
int main () {
	int h, w;
	cin >> h >> w;
	char arr[h + 1][w + 1] = {};
	for (int i = 1; i <= h; i++) for (int j = 1; j <= w; j++) cin >> arr[i][j];
	int ans = 0;
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			if (arr[i][j] != '.') {
				queue <pair <int, int>> cur;
				cur.push({i, j});
				set <char> p;
				while (!cur.empty()) {
					auto k = cur.front();
					cur.pop();
					if (k.first < 1 || k.first > h) continue;
					if (k.second < 1 || k.second > w) continue;
					if (arr[k.first][k.second] == '.') continue;
					p.insert(arr[k.first][k.second]);
					arr[k.first][k.second] = '.';
					for (int i = 0; i < 4; i++) {
						cur.push({k.first + dx[i], k.second + dy[i]});
					}
				}
				ans += p.size();
			}
		}
	}
	cout << ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...