124272024-12-17 14:48:4942Síkság (55)python3Accepted 55/55135ms14528 KiB
import sys
input=sys.stdin.readline
def s():
 input()
 A=list(map(int,input().split()))
 S=0
 L=1
 d={A[0]:1}
 R=0
 for i in range(1,len(A)):
  d[A[i]]=d.get(A[i],0)+1
  while len(d)>2:
   d[A[R]]-=1
   if d[A[R]]==0:del d[A[R]]
   R+=1
  B=list(d.keys())
  if len(B)==2:
   if abs(B[0]-B[1])>1:
    while len(d)>1:
     d[A[R]]-=1
     if d[A[R]]==0:del d[A[R]]
     R+=1
  if i-R+1>L:L,S=i-R+1,R
 print(L,S+1)
s()
SubtaskSumTestVerdictTimeMemory
base55/55
1Accepted0/016ms3128 KiB
2Accepted0/028ms4152 KiB
3Accepted2/216ms3144 KiB
4Accepted2/216ms3120 KiB
5Accepted2/216ms3132 KiB
6Accepted2/216ms3128 KiB
7Accepted3/317ms3168 KiB
8Accepted2/217ms3132 KiB
9Accepted3/317ms3088 KiB
10Accepted3/328ms4392 KiB
11Accepted3/325ms3640 KiB
12Accepted3/325ms3896 KiB
13Accepted3/3128ms14464 KiB
14Accepted3/3112ms4904 KiB
15Accepted3/3128ms11460 KiB
16Accepted3/3131ms14084 KiB
17Accepted3/3129ms14144 KiB
18Accepted3/3135ms14528 KiB
19Accepted3/3127ms13832 KiB
20Accepted3/3130ms13940 KiB
21Accepted3/378ms8828 KiB
22Accepted3/3104ms11992 KiB