結果

問題 No.1361 [Zelkova 4th Tune *] QUADRUPLE-SEQUENCEの詩
ユーザー 👑 KazunKazun
提出日時 2020-11-01 17:58:34
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 2,960 bytes
コンパイル時間 439 ms
コンパイル使用メモリ 81,664 KB
実行使用メモリ 223,188 KB
最終ジャッジ日時 2024-12-27 18:37:54
合計ジャッジ時間 106,122 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 42 TLE * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

def Binary_Search_Small_Count(A,x,equal=False,sort=False):
    """2分探索によって,x未満の要素の個数を調べる.

    A:リスト
    x:調べる要素
    sort:ソートをする必要があるかどうか(Trueで必要)
    equal:Trueのときはx"未満"がx"以下"になる
    """
    if sort:
        A.sort()

    if A[0]>x or ((not equal) and A[0]==x):
        return 0

    L,R=0,len(A)
    while R-L>1:
        C=L+(R-L)//2
        if A[C]<x or (equal and A[C]==x):
            L=C
        else:
            R=C

    return L+1

def Binary_Search_Big_Count(A,x,equal=False,sort=False):
    """2分探索によって,xを超える要素の個数を調べる.

    A:リスト
    x:調べる要素
    sort:ソートをする必要があるかどうか(Trueで必要)
    equal:Trueのときはx"を超える"がx"以上"になる
    """

    if sort:
        A.sort()

    if A[-1]<x or ((not equal) and A[-1]==x):
        return 0

    L,R=-1,len(A)-1
    while R-L>1:
        C=L+(R-L)//2
        if A[C]>x or (equal and A[C]==x):
            R=C
        else:
            L=C
    return len(A)-R

def General_Binary_Increase_Search(L,R,cond,Integer=True,ep=1/(1<<20)):
    """条件式が単調増加であるとき,一般的な二部探索を行う.
    L:解の下限
    R:解の上限
    cond:条件(1変数関数,広義単調減少 or 広義単調減少を満たす)
    Integer:解を整数に制限するか?
    ep:Integer=Falseのとき,解の許容する誤差
    """
    if not(cond(R)):
        return False

    if Integer:
        R+=1
        while R-L>1:
            C=L+(R-L)//2
            if cond(C):
                R=C
            else:
                L=C
        return R
    else:
        while (R-L)>=ep:
            C=L+(R-L)/2
            if cond(C):
                R=C
            else:
                L=C
        return R
#=================================================
def g(x):
    S=0
    for u in U:
        if u>0:
            S+=Binary_Search_Small_Count(V,x//u,True)
        elif u<0:
            S+=Binary_Search_Big_Count(V,(-x-u-1)//(-u),True)
        else:
            if x>=0:
                S+=len(V)
    return S

def h(A,B,x):
    G=set(B)
    b=B[0]

    for a in A:
        if a==0:
            if x==0:
                return (0,b)
        elif (x%a==0) and (x//a in G):
            return (a,x//a)
    return None
#=================================================
import sys
input=sys.stdin.readline

K,L,M,N,P=map(int,input().split())

A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
D=list(map(int,input().split()))

U=[a*b for a in A for b in B]
V=[c*d for c in C for d in D]
V.sort()

E_abs_max=max(U,key=lambda u:abs(u))*max(V,key=lambda v:abs(v))
E_abs_max=abs(E_abs_max)+1

J=General_Binary_Increase_Search(-E_abs_max,E_abs_max,lambda x:g(x)>=P,True)

p,q=h(U,V,J)
a,b=h(A,B,p)
c,d=h(C,D,q)

print(J)
print(a,b,c,d)
0