193812025-12-06 22:17:28birozsCseppkőbarlang (45 pont)pypy3Hibás válasz 30/45294ms28732 KiB
N,M = map(int,input().split())
null = [0]*(M+2)
T = [null]
for _ in range(N):
    sor = list(map(int,input().split()))
    sor = [0] + sor + [0]
    T.append(sor)
T.append(null)
resz = 0
Indul = []
for i in range(1,N+1):
    for j in range(1,M+1):
        Szomszed = []
        if T[i][j] != 0:
            if T[i-1][j] != 0:
                Szomszed.append(T[i-1][j])
            if T[i+1][j] != 0:
                Szomszed.append(T[i+1][j])
            if T[i][j-1] != 0:
                Szomszed.append(T[i][j-1])
            if T[i][j+1] != 0:
                Szomszed.append(T[i][j+1])
            if len(Szomszed) > 0 and T[i][j] < min(Szomszed):
                Indul.append([i,j])
                resz += 1
                sor = [[i,j,T[i][j]]]
                Volt = [[i,j]]
                while sor:
                    akt = sor.pop()
                    #print(akt)
                    x = akt[0]
                    y = akt[1]
                    m = akt[2]
                    T[x][y] = 0
                    if T[x-1][y] >= m and [x-1,y,T[x-1][y]] not in Volt:
                        sor.append([x-1,y,T[x-1][y]])
                        Volt.append([x-1,y,T[x-1][y]])
                    if T[x+1][y] >= m and [x+1,y,T[x+1][y]] not in Volt:
                        sor.append([x+1,y,T[x+1][y]])
                        Volt.append([x+1,y,T[x+1][y]])
                    if T[x][y+1] >= m and [x,y+1,T[x][y+1]] not in Volt:
                        sor.append([x,y+1,T[x][y+1]])
                        Volt.append([x,y+1,T[x][y+1]])
                    if T[x][y-1] >= m and [x,y-1,T[x][y-1]] not in Volt:
                        sor.append([x,y-1,T[x][y-1]])  
                        Volt.append([x,y-1,T[x][y-1]])  
                #a = input()
for i in range(1,N+1):
    for j in range(1,M+1):
        if T[i][j] != 0:
            Indul.append([i,j])
            resz += 1
            m = T[i][j]
            sor = [[i,j]]
            T[i][j] = 0
            while sor:
                akt = sor.pop()
                x = akt[0]
                y = akt[1]
                if T[x-1][y] != 0:
                    sor.append([x-1,y])
                    T[x-1][y] = 0
                if T[x+1][y] != 0:
                    sor.append([x+1,y])
                    T[x+1][y] = 0  
                if T[x][y-1] != 0:
                    sor.append([x,y-1])
                    T[x][y-1] = 0
                if T[x][y+1] != 0:
                    sor.append([x,y+1])
                    T[x][y+1] = 0
                             

print(resz)
#Indul.sort()
for i,j in Indul:
    print(i,j)      
RészfeladatÖsszpontTesztVerdiktIdőMemória
base30/45
1Elfogadva0/043ms21184 KiB
2Elfogadva0/050ms21428 KiB
3Elfogadva1/146ms21240 KiB
4Elfogadva1/143ms21324 KiB
5Elfogadva2/2202ms25568 KiB
6Elfogadva2/2203ms25832 KiB
7Elfogadva2/2225ms25828 KiB
8Elfogadva2/245ms21260 KiB
9Elfogadva2/252ms21232 KiB
10Elfogadva3/3206ms26344 KiB
11Elfogadva3/3261ms27876 KiB
12Elfogadva3/3256ms27364 KiB
13Elfogadva3/3254ms27128 KiB
14Elfogadva3/3141ms24296 KiB
15Hibás válasz0/3266ms27788 KiB
16Hibás válasz0/3294ms28732 KiB
17Hibás válasz0/3247ms27984 KiB
18Hibás válasz0/3244ms28136 KiB
19Hibás válasz0/3226ms25832 KiB
20Elfogadva3/3250ms28240 KiB