124182024-12-17 14:29:3242Síkság (55)python3Wrong answer 36/55138ms14640 KiB
# O(N)
from sys import stdin
input=stdin.readline

def solv():
    N=int(input())
    A=list(map(int,input().split()))

    start=0
    length=1

    d={A[0]:1}
    last=0
    for i in range(1,len(A)):
        d[A[i]]=d.get(A[i],0)+1
        while len(d)>2:
            d[A[last]]-=1
            if d[A[last]]==0:
                del d[A[last]]
            last+=1
        AA=list(d.keys())
        if len(AA)==2:
            if abs(AA[0]-AA[1])>1:
                while len(d)>2:
                    d[A[last]]-=1
                    if d[A[last]]==0:
                        del d[A[last]]
                    last+=1
        if i-last+1>length:
            length=i-last+1
            start=last
            
    print(length,start+1)

solv()
SubtaskSumTestVerdictTimeMemory
base36/55
1Accepted0/016ms3124 KiB
2Accepted0/028ms4164 KiB
3Wrong answer0/216ms3120 KiB
4Accepted2/216ms3128 KiB
5Wrong answer0/216ms3312 KiB
6Accepted2/216ms3320 KiB
7Accepted3/317ms3128 KiB
8Accepted2/217ms3128 KiB
9Wrong answer0/317ms3216 KiB
10Accepted3/328ms4276 KiB
11Accepted3/325ms3576 KiB
12Accepted3/325ms3920 KiB
13Wrong answer0/3134ms14640 KiB
14Accepted3/3112ms5016 KiB
15Accepted3/3128ms11520 KiB
16Accepted3/3131ms14132 KiB
17Wrong answer0/3128ms14156 KiB
18Wrong answer0/3138ms14132 KiB
19Accepted3/3133ms13860 KiB
20Accepted3/3134ms13896 KiB
21Accepted3/376ms8976 KiB
22Wrong answer0/3108ms12008 KiB