82412024-01-13 19:19:33mmatedCseppkőbarlang (45 pont)cpp17Accepted 45/4527ms9740 KiB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf INT_MAX
#define f(i,k,n) for(int i=k; i<n; i++)

vector<vector<int>> g;
vector<vector<int>> v;
int n,m;
void cucc(int a, int b, vector<vector<int>> &v)
{
    if(!v[a][b])
    {
        v[a][b]=1;
        int k=0;
        if(a>0 && !v[a-1][b] && g[a][b]<=g[a-1][b])  cucc(a-1,b,v);
        if(b>0 && !v[a][b-1] && g[a][b]<=g[a][b-1])  cucc(a,b-1,v);
        if(a<n-1 && !v[a+1][b] && g[a][b]<=g[a+1][b])  cucc(a+1,b,v);
        if(b<m-1 && !v[a][b+1] && g[a][b]<=g[a][b+1])  cucc(a,b+1,v);
    }
}
void solve()
{
    cin>>n>>m;
    g.resize(n,vector<int>(m));
    v.resize(n,vector<int>(m));
    vector<vector<int>> asd;
    f(i,0,n)
        f(j,0,m)
        {
            cin>>g[i][j];
            if(g[i][j])   asd.push_back({g[i][j],i,j});
            v[i][j]=0;
        }
    sort(asd.begin(),asd.end());
    vector<vector<int>> ans;
    f(i,0,asd.size())
    {
        if(!v[asd[i][1]][asd[i][2]])
        {
            ans.push_back({asd[i][1],asd[i][2]});
            cucc(asd[i][1],asd[i][2],v);
        }
    }
    cout<<ans.size()<<"\n";
    for(vector<int> q : ans)    cout<<q[0]+1<<" "<<q[1]+1<<"\n";
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    //cin>>t;
    while(t--)  solve();
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base45/45
1Accepted0/03ms1828 KiB
2Accepted0/03ms2224 KiB
3Accepted1/13ms2268 KiB
4Accepted1/13ms2448 KiB
5Accepted2/214ms8156 KiB
6Accepted2/214ms6624 KiB
7Accepted2/214ms7196 KiB
8Accepted2/23ms3020 KiB
9Accepted2/23ms2944 KiB
10Accepted3/317ms7148 KiB
11Accepted3/327ms9188 KiB
12Accepted3/320ms8320 KiB
13Accepted3/320ms8008 KiB
14Accepted3/312ms5720 KiB
15Accepted3/320ms8720 KiB
16Accepted3/320ms8924 KiB
17Accepted3/321ms9036 KiB
18Accepted3/321ms9020 KiB
19Accepted3/318ms8628 KiB
20Accepted3/324ms9740 KiB