115772024-10-27 12:40:56balintCsúcsokpython3Időlimit túllépés 16/1001.085s18324 KiB
def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    # Create the height matrix H[i][j] = A[i] * B[j]
    # heights = [[A[i] + B[j] for j in range(M)] for i in range(N)]
    peaks = 0
    def height(i, j):
        # give the current position's height if in map else 0
        return (A[i] + B[j] if 0 <= i < N and 0 <= j < M else 0)
    
    def is_peak(a,b,c,d,e,f,g,h,i):
        return e > max(a, b, c, d, f, g, h, i)
        # return e > a and e > b and e > c and e > d and e > f and e > g and e > h and e > i

    
    # Iterate through each cell to check for peaks
    a, b, c, d, e, f, g, h, i = 0, 0, 0, 0, height(0,0), height(0,1), 0, height(1,0), height(1,1) 
    peaks += is_peak(a,b,c,d,e,f,g,h,i)

    # Iterate from top to bottom (each iteration left to right, down, right to left, down)
    for N_i in range(0, N, 2):
        # scroll right
        for M_i in range(M-1):
            a,b,c = b,c, height(N_i-1, M_i+2)
            d,e,f, = e,f, height(N_i, M_i+2)
            g,h,i = h,i, height(N_i+1, M_i+2)

            peaks += is_peak(a,b,c,d,e,f,g,h,i)

        # reached end at bottom right
        if height(N_i+2, M_i+1) == 0:
            break

        # scroll down
        a,b,c = d,e,f
        d,e,f = g,h,i
        g,h,i = height(N_i+2, M_i), height(N_i+2, M_i+1), height(N_i+2, M_i+2)
        peaks += is_peak(a,b,c,d,e,f,g,h,i)

        # scroll left
        for M_i in range(M_i, -1, -1):
            a,b,c = height(N_i, M_i-1),a,b
            d,e,f, = height(N_i+1, M_i-1), d,e
            g,h,i = height(N_i+2, M_i-1), g,h

            peaks += is_peak(a,b,c,d,e,f,g,h,i)

        # reached end at bottom left
        if height(N_i+2, M_i) == 0:
            break

        # scroll down
        a,b,c = d,e,f
        d,e,f = g,h,i
        g,h,i = height(N_i+3, M_i-1), height(N_i+3, M_i), height(N_i+3, M_i+1)
        peaks += is_peak(a,b,c,d,e,f,g,h,i)

    print(peaks)

main()
RészfeladatÖsszpontTesztVerdiktIdőMemória
subtask10/0
1Elfogadva17ms3132 KiB
2Elfogadva16ms3128 KiB
subtask216/16
3Elfogadva150ms14792 KiB
4Elfogadva141ms13376 KiB
5Elfogadva135ms6060 KiB
6Elfogadva150ms14876 KiB
7Elfogadva143ms14784 KiB
8Elfogadva144ms14444 KiB
subtask30/33
9Időlimit túllépés1.078s3384 KiB
10Időlimit túllépés1.08s3576 KiB
11Időlimit túllépés1.08s3372 KiB
12Hibás válasz17ms3380 KiB
13Futási hiba16ms3336 KiB
14Elfogadva17ms3384 KiB
15Időlimit túllépés1.077s3576 KiB
subtask40/51
16Időlimit túllépés1.075s18080 KiB
17Időlimit túllépés1.075s15180 KiB
18Időlimit túllépés1.075s18076 KiB
19Elfogadva319ms14708 KiB
20Hibás válasz160ms14876 KiB
21Időlimit túllépés1.085s18064 KiB
22Időlimit túllépés1.083s18324 KiB
23Időlimit túllépés1.085s17604 KiB
24Időlimit túllépés1.085s17788 KiB