結果

問題 No.2500 Products in a Range
ユーザー titiatitia
提出日時 2023-10-13 23:30:04
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,209 bytes
コンパイル時間 301 ms
コンパイル使用メモリ 86,984 KB
実行使用メモリ 83,428 KB
最終ジャッジ日時 2023-10-13 23:30:22
合計ジャッジ時間 15,661 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
78,308 KB
testcase_01 AC 74 ms
71,360 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 653 ms
80,572 KB
testcase_08 AC 874 ms
80,304 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 TLE -
testcase_12 WA -
testcase_13 AC 171 ms
77,632 KB
testcase_14 AC 1,547 ms
80,912 KB
testcase_15 AC 203 ms
77,760 KB
testcase_16 AC 133 ms
78,108 KB
testcase_17 AC 131 ms
78,148 KB
testcase_18 AC 132 ms
78,196 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 TLE -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect,bisect_left

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

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

ANS=0

for i in range(len(PLUS)):
    for ind in range(i,len(PLUS)):
        if check(i,ind,PLUS)==False:
            break
        
        k0=PLUS[i]
        k1=PLUS[ind]

        if l>=0:
            MIN=max(l//k0,l//k1)
        else:
            MIN=max((l+k0-1)//k0,(l+k1-1)//k1)

        if r>=0:
            MAX=min(r//k0,r//k1)
        else:
            MAX=min((r+k0-1)//k0,(r+k1-1)//k1)

        plus=0

        if MIN<=MAX:
            x0=bisect_left(MINUS,MIN)
            x1=bisect(MINUS,MAX)

            plus=x1-x0

        #print(i,ind,MIN,MAX,plus)

        ANS=max(ANS,ind-i+1+plus)

for i in range(len(MINUS)):
    for ind in range(i,len(MINUS)):
        if check(i,ind,MINUS)==False:
            break
        
        k0=MINUS[i]
        k1=MINUS[ind]

        if l<0:
            MAX=min(l//k0,l//k1)
        else:
            MAX=min((l+k0-1)//k0,(l+k1-1)//k1)

        if r<0:
            MIN=max(r//k0,r//k1)
        else:
            MIN=max((r+k0-1)//k0,(r+k1-1)//k1)

        plus=0

        if MIN<=MAX:
            x0=bisect_left(PLUS,MIN)
            x1=bisect(PLUS,MAX)

            plus=x1-x0

        #print(i,ind,k0,k1,MIN,MAX,plus)

        ANS=max(ANS,ind-i+1+plus)

if l<=0<=r:
    ANS+=zero
    
print(ANS)
    

    
0