82412024-01-13 19:19:33mmatedCseppkőbarlang (45 pont)cpp17Elfogadva 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;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base45/45
1Elfogadva0/03ms1828 KiB
2Elfogadva0/03ms2224 KiB
3Elfogadva1/13ms2268 KiB
4Elfogadva1/13ms2448 KiB
5Elfogadva2/214ms8156 KiB
6Elfogadva2/214ms6624 KiB
7Elfogadva2/214ms7196 KiB
8Elfogadva2/23ms3020 KiB
9Elfogadva2/23ms2944 KiB
10Elfogadva3/317ms7148 KiB
11Elfogadva3/327ms9188 KiB
12Elfogadva3/320ms8320 KiB
13Elfogadva3/320ms8008 KiB
14Elfogadva3/312ms5720 KiB
15Elfogadva3/320ms8720 KiB
16Elfogadva3/320ms8924 KiB
17Elfogadva3/321ms9036 KiB
18Elfogadva3/321ms9020 KiB
19Elfogadva3/318ms8628 KiB
20Elfogadva3/324ms9740 KiB