193822025-12-06 22:22:18birozsCseppkőbarlang (45 pont)pypy3Hibás válasz 30/45291ms28188 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] == m:
                    sor.append([x-1,y])
                    T[x-1][y] = 0
                if T[x+1][y] == m:
                    sor.append([x+1,y])
                    T[x+1][y] = 0  
                if T[x][y-1] == m:
                    sor.append([x,y-1])
                    T[x][y-1] = 0
                if T[x][y+1] == m:
                    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/043ms21420 KiB
2Elfogadva0/056ms21464 KiB
3Elfogadva1/143ms21124 KiB
4Elfogadva1/148ms21204 KiB
5Elfogadva2/2212ms25416 KiB
6Elfogadva2/2202ms25524 KiB
7Elfogadva2/2199ms25788 KiB
8Elfogadva2/246ms21172 KiB
9Elfogadva2/252ms21228 KiB
10Elfogadva3/3203ms26600 KiB
11Elfogadva3/3277ms28036 KiB
12Elfogadva3/3259ms27336 KiB
13Elfogadva3/3254ms27016 KiB
14Elfogadva3/3138ms24396 KiB
15Hibás válasz0/3252ms28152 KiB
16Hibás válasz0/3291ms28132 KiB
17Hibás válasz0/3266ms27880 KiB
18Hibás válasz0/3243ms28188 KiB
19Hibás válasz0/3225ms26088 KiB
20Elfogadva3/3250ms27964 KiB