193802025-12-06 21:53:19birozsCseppkőbarlang (45 pont)pypy3Wrong answer 18/45272ms29212 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           
print(resz)
#Indul.sort()
for i,j in Indul:
    print(i,j)      
SubtaskSumTestVerdictTimeMemory
base18/45
1Accepted0/043ms21384 KiB
2Accepted0/050ms21516 KiB
3Wrong answer0/143ms19912 KiB
4Wrong answer0/148ms21100 KiB
5Wrong answer0/2190ms29160 KiB
6Wrong answer0/2164ms28368 KiB
7Wrong answer0/2178ms28180 KiB
8Wrong answer0/248ms21088 KiB
9Wrong answer0/257ms21700 KiB
10Accepted3/3203ms26340 KiB
11Accepted3/3272ms27960 KiB
12Accepted3/3245ms27740 KiB
13Accepted3/3252ms27284 KiB
14Accepted3/3138ms24548 KiB
15Wrong answer0/3252ms27504 KiB
16Wrong answer0/3266ms29212 KiB
17Wrong answer0/3256ms27368 KiB
18Wrong answer0/3241ms28140 KiB
19Wrong answer0/3215ms26092 KiB
20Accepted3/3256ms27844 KiB