193842025-12-07 07:37:03birozsCseppkőbarlang (45 pont)pypy3Időlimit túllépés 39/45584ms28392 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):
        if T[i][j] > 0:
            #print(T[i][j])
            resz += 1
            kezdo = [i,j,T[i][j]]
            MinCsucs = kezdo[:]
            sor = [kezdo]
            Volt = [kezdo]
            while sor:
                akt = sor.pop()
                x = akt[0]
                y = akt[1]
                m = akt[2]
                if 0 < 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] < MinCsucs[2]:
                        MinCsucs = [x-1,y,T[x-1][y]]
                if 0 < 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] < MinCsucs[2]:
                        MinCsucs = [x+1,y,T[x+1][y]]
                if 0 < 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] < MinCsucs[2]:
                        MinCsucs = [x,y+1,T[x][y+1]]
                if 0 < 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] < MinCsucs[2]:
                        MinCsucs = [x,y-1,T[x][y-1]]
            Indul.append(MinCsucs)
            sor = [MinCsucs]
            Volt = [MinCsucs]
            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()
print(resz)
for i,j,m in Indul:
    print(i,j)      
RészfeladatÖsszpontTesztVerdiktIdőMemória
base39/45
1Elfogadva0/050ms21804 KiB
2Elfogadva0/050ms21660 KiB
3Elfogadva1/148ms21472 KiB
4Elfogadva1/146ms21688 KiB
5Időlimit túllépés0/2583ms23964 KiB
6Időlimit túllépés0/2584ms28368 KiB
7Időlimit túllépés0/2584ms24808 KiB
8Elfogadva2/257ms21756 KiB
9Elfogadva2/267ms21992 KiB
10Elfogadva3/3239ms28392 KiB
11Elfogadva3/3275ms28392 KiB
12Elfogadva3/3238ms27112 KiB
13Elfogadva3/3246ms26988 KiB
14Elfogadva3/3143ms25040 KiB
15Elfogadva3/3263ms28136 KiB
16Elfogadva3/3263ms28136 KiB
17Elfogadva3/3231ms27368 KiB
18Elfogadva3/3256ms28064 KiB
19Elfogadva3/3218ms27632 KiB
20Elfogadva3/3247ms28136 KiB