231992026-01-16 16:47:32GervidCseppkőbarlang (45 pont)cpp17Accepted 45/4519ms1760 KiB
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <limits.h>
#include <algorithm>
#include <math.h>
#include <array>

using namespace std;
using ll = long long;

vector<vector<int>> grid;
vector<vector<bool>> handled;
vector<array<int, 2>> neighbours = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} };
vector<array<int, 2>> ans;
vector<array<int, 3>> tiles; //depth, x, y

bool inbound(int x, int y) {
	return 0 <= x && x < grid.size() && 0 <= y && y < grid[0].size();
}

void dfs(int nodex, int nodey) {
	handled[nodex][nodey] = true;
	for (array<int, 2> neighbour : neighbours) {
		int neighx = nodex + neighbour[0], neighy = nodey + neighbour[1];
		if (inbound(neighx, neighy) && !handled[neighx][neighy] && grid[nodex][nodey] <= grid[neighx][neighy]) {
			dfs(neighx, neighy);
		}
	}
}

signed main()
{
	iostream::sync_with_stdio(0);
	cin.tie(0);

	int n, m;
	cin >> n >> m;
	grid.resize(n, vector<int>(m));
	handled.resize(n, vector<bool>(m, false));
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			cin >> grid[i][j], handled[i][j] = grid[i][j] == 0, tiles.push_back({ grid[i][j], i, j });

	sort(tiles.begin(), tiles.end());
	for (int i = 0; i < tiles.size(); i++) {
		if (!handled[tiles[i][1]][tiles[i][2]]) {
			dfs(tiles[i][1], tiles[i][2]);
			ans.push_back({ tiles[i][1], tiles[i][2] });
		}
	}
	cout << ans.size() << '\n';
	for (int i = 0; i < ans.size(); i++) {
		cout << ans[i][0] + 1 << ' ' << ans[i][1] + 1 << '\n';
	}
}
SubtaskSumTestVerdictTimeMemory
base45/45
1Accepted0/01ms316 KiB
2Accepted0/01ms508 KiB
3Accepted1/11ms316 KiB
4Accepted1/11ms316 KiB
5Accepted2/217ms1760 KiB
6Accepted2/217ms1376 KiB
7Accepted2/216ms1492 KiB
8Accepted2/21ms316 KiB
9Accepted2/21ms316 KiB
10Accepted3/317ms1456 KiB
11Accepted3/319ms1384 KiB
12Accepted3/316ms1328 KiB
13Accepted3/316ms1332 KiB
14Accepted3/314ms1520 KiB
15Accepted3/318ms1444 KiB
16Accepted3/317ms1452 KiB
17Accepted3/318ms1372 KiB
18Accepted3/318ms1452 KiB
19Accepted3/317ms1452 KiB
20Accepted3/318ms1456 KiB