結果

問題 No.2500 Products in a Range
ユーザー titiatitia
提出日時 2023-10-14 02:44:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,106 ms / 2,000 ms
コード長 2,021 bytes
コンパイル時間 440 ms
コンパイル使用メモリ 86,856 KB
実行使用メモリ 78,112 KB
最終ジャッジ日時 2023-10-14 02:44:54
合計ジャッジ時間 20,516 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,024 KB
testcase_01 AC 75 ms
71,112 KB
testcase_02 AC 133 ms
77,096 KB
testcase_03 AC 93 ms
76,312 KB
testcase_04 AC 105 ms
76,744 KB
testcase_05 AC 108 ms
76,624 KB
testcase_06 AC 94 ms
76,200 KB
testcase_07 AC 243 ms
78,048 KB
testcase_08 AC 620 ms
78,112 KB
testcase_09 AC 115 ms
76,876 KB
testcase_10 AC 511 ms
78,032 KB
testcase_11 AC 602 ms
77,812 KB
testcase_12 AC 296 ms
77,672 KB
testcase_13 AC 131 ms
77,608 KB
testcase_14 AC 869 ms
78,080 KB
testcase_15 AC 163 ms
77,792 KB
testcase_16 AC 255 ms
77,252 KB
testcase_17 AC 375 ms
77,612 KB
testcase_18 AC 178 ms
77,124 KB
testcase_19 AC 186 ms
76,356 KB
testcase_20 AC 206 ms
76,280 KB
testcase_21 AC 87 ms
76,412 KB
testcase_22 AC 1,095 ms
77,956 KB
testcase_23 AC 1,097 ms
77,840 KB
testcase_24 AC 1,106 ms
77,664 KB
testcase_25 AC 851 ms
77,696 KB
testcase_26 AC 848 ms
77,924 KB
testcase_27 AC 830 ms
78,088 KB
testcase_28 AC 177 ms
76,096 KB
testcase_29 AC 100 ms
76,320 KB
testcase_30 AC 93 ms
76,200 KB
testcase_31 AC 95 ms
76,212 KB
testcase_32 AC 81 ms
76,008 KB
testcase_33 AC 265 ms
77,300 KB
testcase_34 AC 513 ms
77,348 KB
testcase_35 AC 76 ms
71,020 KB
testcase_36 AC 73 ms
71,072 KB
testcase_37 AC 73 ms
71,172 KB
testcase_38 AC 71 ms
70,992 KB
testcase_39 AC 73 ms
71,036 KB
testcase_40 AC 70 ms
71,176 KB
testcase_41 AC 70 ms
70,912 KB
testcase_42 AC 72 ms
70,952 KB
testcase_43 AC 71 ms
70,956 KB
testcase_44 AC 89 ms
76,308 KB
testcase_45 AC 77 ms
75,956 KB
testcase_46 AC 92 ms
76,304 KB
testcase_47 AC 810 ms
77,788 KB
testcase_48 AC 77 ms
75,516 KB
testcase_49 AC 115 ms
76,140 KB
testcase_50 AC 195 ms
77,004 KB
testcase_51 AC 242 ms
77,516 KB
testcase_52 AC 325 ms
77,496 KB
testcase_53 AC 150 ms
77,296 KB
testcase_54 AC 81 ms
75,964 KB
testcase_55 AC 196 ms
77,116 KB
testcase_56 AC 210 ms
77,324 KB
testcase_57 AC 438 ms
77,024 KB
testcase_58 AC 126 ms
77,296 KB
testcase_59 AC 345 ms
77,296 KB
testcase_60 AC 106 ms
76,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,l,r=map(int,input().split())
A=list(map(int,input().split()))

ANS=1
for i in range(n):
    for j in range(i+1,n):
        if l<=A[i]*A[j]<=r:
            ANS=2

if r<0:
    print(ANS)
    exit()

PLUS=[]
MINUS=[]
zero=0

for a in A:
    if a>0:
        PLUS.append(a)
    elif a<0:
        MINUS.append(a)
    else:
        zero+=1
    
PLUS.sort()
MINUS.sort()

def check(x,y,A):
    for i in range(x+1,x+3):
        if x<=i<=y:
            if x!=i:
                if l<=A[x]*A[i]<=r:
                    pass
                else:
                    return False
            if y!=i:
                if l<=A[y]*A[i]<=r:
                    pass
                else:
                    return False

    for i in range(y-2,y):
        if x<=i<=y:
            if x!=i:
                if l<=A[x]*A[i]<=r:
                    pass
                else:
                    return False
            if y!=i:
                if l<=A[y]*A[i]<=r:
                    pass
                else:
                    return False

    return True

if l>0:
    for i in range(len(PLUS)):
        for j in range(i,len(PLUS)):
            if check(i,j,PLUS)==True:
                ANS=max(ANS,j-i+1)

    for i in range(len(MINUS)):
        for j in range(i,len(MINUS)):
            if check(i,j,MINUS)==True:
                ANS=max(ANS,j-i+1)

    print(ANS)
    exit()

MINUS.reverse()
ANS=0
for i in range(len(PLUS)+1):
    for j in range(len(MINUS)+1):
        x0=0
        if i-2>=0:
            x0=PLUS[i-2]
        x1=0
        if i-1>=0:
            x1=PLUS[i-1]

        y0=0
        if j-2>=0:
            y0=MINUS[j-2]
        y1=0
        if j-1>=0:
            y1=MINUS[j-1]

        LIST=[x0,x1,y0,y1]

        flag=1

        for k in range(4):
            for m in range(k+1,4):
                if l<=LIST[k]*LIST[m]<=r:
                    pass
                else:
                    flag=0

        if flag==1:
            ANS=max(ANS,i+j)

print(ANS+zero)

        
        
        
            
    
0