199132025-12-29 14:04:17AblablablaCseppkőbarlang (45 pont)cpp17Accepted 45/4529ms1804 KiB
#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;

struct adat{
    int ert, x, y;
};

struct comp{
    bool operator()(adat a, adat b){
        return a.ert < b.ert;
    }
};

vector<vector<int>> alap;
vector<vector<bool>> bejart;

vector<int> xIrany = {0, 1, 0, -1};
vector<int> yIrany = {1, 0, -1, 0};

void dfs(int x, int y){
    bejart[x][y] = 1;

    for(int i = 0; i < 4; i++){
        int ujX = x + xIrany[i];
        int ujY = y + yIrany[i];

        if(bejart[ujX][ujY]) continue;
        if(alap[ujX][ujY] < alap[x][y]){
            continue;
        }


        dfs(ujX, ujY);
    }
}

int main()
{
    int n, m;
    cin >> n >> m;

    alap.assign(n + 2, vector<int>(m + 2, 0));
    bejart.assign(n + 2, vector<bool>(m + 2, 0));
    vector<adat> szamok;

    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cin >> alap[i][j];

            if(alap[i][j] != 0){
                szamok.push_back({alap[i][j], i, j});
            }
        }
    }


    sort(szamok.begin(), szamok.end(), comp());

    vector<pii> ans;

    for(adat x : szamok){
        if(!bejart[x.x][x.y]){
            dfs(x.x, x.y);
            ans.push_back({x.x, x.y});
        }
    }

    cout << ans.size() << "\n";
    for(auto x : ans){
        cout << x.first << " " << x.second << "\n";
    }
}
SubtaskSumTestVerdictTimeMemory
base45/45
1Accepted0/01ms500 KiB
2Accepted0/01ms316 KiB
3Accepted1/11ms316 KiB
4Accepted1/11ms316 KiB
5Accepted2/214ms1804 KiB
6Accepted2/214ms1064 KiB
7Accepted2/213ms1236 KiB
8Accepted2/21ms316 KiB
9Accepted2/21ms316 KiB
10Accepted3/320ms1012 KiB
11Accepted3/329ms1328 KiB
12Accepted3/324ms988 KiB
13Accepted3/323ms1072 KiB
14Accepted3/316ms820 KiB
15Accepted3/316ms1076 KiB
16Accepted3/314ms1076 KiB
17Accepted3/317ms1072 KiB
18Accepted3/317ms1016 KiB
19Accepted3/316ms1060 KiB
20Accepted3/328ms1312 KiB