193832025-12-06 22:31:06birozsCseppkőbarlang (45 pont)pypy3Hibás válasz 30/45296ms28804 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,m]]
            T[i][j] = 0
            while sor:
                akt = sor.pop()
                x = akt[0]
                y = akt[1]
                m = akt[2]
                if T[x-1][y] >= m:
                    sor.append([x-1,y,T[x-1][y]])
                    T[x-1][y] = 0
                if T[x+1][y] >= m:
                    sor.append([x+1,y,T[x+1][y]])
                    T[x+1][y] = 0  
                if T[x][y-1] >= m:
                    sor.append([x,y-1,T[x][y-1]])
                    T[x][y-1] = 0
                if T[x][y+1] >= m:
                    sor.append([x,y+1,T[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/043ms21672 KiB
2Elfogadva0/057ms21724 KiB
3Elfogadva1/148ms21472 KiB
4Elfogadva1/143ms21476 KiB
5Elfogadva2/2239ms25608 KiB
6Elfogadva2/2200ms26152 KiB
7Elfogadva2/2216ms26096 KiB
8Elfogadva2/252ms21412 KiB
9Elfogadva2/254ms21480 KiB
10Elfogadva3/3209ms26344 KiB
11Elfogadva3/3273ms28140 KiB
12Elfogadva3/3245ms27872 KiB
13Elfogadva3/3254ms27368 KiB
14Elfogadva3/3143ms24536 KiB
15Hibás válasz0/3264ms28136 KiB
16Hibás válasz0/3296ms28804 KiB
17Hibás válasz0/3250ms28136 KiB
18Hibás válasz0/3246ms28492 KiB
19Hibás válasz0/3225ms26344 KiB
20Elfogadva3/3248ms28152 KiB