結果

問題 No.1361 [Zelkova 4th Tune *] QUADRUPLE-SEQUENCEの詩
ユーザー 👑 KazunKazun
提出日時 2020-10-21 04:30:22
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 4,371 bytes
コンパイル時間 549 ms
コンパイル使用メモリ 87,240 KB
実行使用メモリ 108,456 KB
最終ジャッジ日時 2023-08-27 16:11:29
合計ジャッジ時間 22,512 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,188 KB
testcase_01 AC 74 ms
71,384 KB
testcase_02 AC 73 ms
71,248 KB
testcase_03 AC 72 ms
71,468 KB
testcase_04 AC 74 ms
71,184 KB
testcase_05 AC 72 ms
71,336 KB
testcase_06 AC 72 ms
71,492 KB
testcase_07 AC 73 ms
71,464 KB
testcase_08 AC 92 ms
76,152 KB
testcase_09 AC 88 ms
76,100 KB
testcase_10 AC 92 ms
76,224 KB
testcase_11 AC 92 ms
75,980 KB
testcase_12 AC 91 ms
76,084 KB
testcase_13 AC 92 ms
76,000 KB
testcase_14 AC 84 ms
75,868 KB
testcase_15 AC 100 ms
77,008 KB
testcase_16 AC 94 ms
76,128 KB
testcase_17 AC 89 ms
76,076 KB
testcase_18 AC 133 ms
78,068 KB
testcase_19 AC 113 ms
77,540 KB
testcase_20 AC 128 ms
78,076 KB
testcase_21 AC 113 ms
78,724 KB
testcase_22 AC 120 ms
78,592 KB
testcase_23 AC 133 ms
79,224 KB
testcase_24 AC 136 ms
80,424 KB
testcase_25 AC 132 ms
79,512 KB
testcase_26 AC 137 ms
79,424 KB
testcase_27 AC 117 ms
77,804 KB
testcase_28 AC 399 ms
108,456 KB
testcase_29 RE -
testcase_30 AC 335 ms
100,260 KB
testcase_31 RE -
testcase_32 RE -
testcase_33 AC 328 ms
98,924 KB
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 AC 253 ms
99,272 KB
testcase_38 AC 355 ms
107,812 KB
testcase_39 AC 283 ms
94,232 KB
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 RE -
testcase_51 RE -
testcase_52 RE -
testcase_53 RE -
testcase_54 RE -
testcase_55 RE -
testcase_56 RE -
testcase_57 RE -
testcase_58 RE -
testcase_59 RE -
testcase_60 RE -
testcase_61 RE -
testcase_62 RE -
testcase_63 RE -
testcase_64 RE -
testcase_65 RE -
testcase_66 RE -
testcase_67 RE -
testcase_68 AC 73 ms
71,312 KB
testcase_69 AC 72 ms
71,320 KB
testcase_70 AC 74 ms
71,380 KB
testcase_71 AC 74 ms
71,340 KB
testcase_72 AC 73 ms
71,028 KB
testcase_73 AC 74 ms
71,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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 f(x): #負の時の判定
    Z=0

    I=0
    for u in U_pos:
        while (I<V_negative and u*V_neg[I]<=x):
            I+=1
        Z+=I

    I=0
    for v in V_pos:
        while (I<U_negative and v*U_neg[I]<=x):
            I+=1
        Z+=I

    return Z

def g(x): #正の時の判定
    Z=0

    I=V_positive
    for u in U_pos:
        while (I>0 and u*V_pos[I-1]>x):
            I-=1
        Z+=I

    I=0
    for v in V_neg:
        while (I<U_negative and v*U_neg[-(I+1)]<=x):
            I+=1
        Z+=I

    return Z
#================================================
# pq=x なる p in G,q in H を求める.
def h(x,G,H):
    if x==0:
        if 0 in G:
            return (0,H[0])
        else:
            return (G[0],0)

    H=set(H)
    for g in G:
        if g==0:
            continue

        if (x%g==0) and (x//g in H):
            return (g,x//g)
    return None
#================================================
#入力
K,L,M,N,S=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()))

#================================================
#制約確認
assert 1<=K<=500,"Kが制約外(K={})".format(K)
assert 1<=L<=500,"Lが制約外(L={})".format(L)
assert 1<=M<=500,"Mが制約外(M={})".format(M)
assert 1<=N<=500,"Nが制約外(N={})".format(N)
assert 1<=S<=K*L*M*N,"Sが制約外(S={})".format(S)

assert len(A)==K,"Aの長さが違う(K={},Aの長さ={})".format(K,len(A))
assert len(B)==L,"Bの長さが違う(L={},Bの長さ={})".format(L,len(B))
assert len(C)==M,"Cの長さが違う(M={},Cの長さ={})".format(M,len(C))
assert len(D)==N,"Dの長さが違う(N={},Dの長さ={})".format(N,len(D))

A_abs_max=abs(max(A,key=lambda a:abs(a)))
B_abs_max=abs(max(B,key=lambda b:abs(b)))
C_abs_max=abs(max(C,key=lambda c:abs(c)))
D_abs_max=abs(max(D,key=lambda d:abs(d)))
assert A_abs_max<=3*10**4,"Aが制約外(max |A|={})".format(A_abs_max)
assert B_abs_max<=3*10**4,"Bが制約外(max |B|={})".format(B_abs_max)
assert C_abs_max<=3*10**4,"Cが制約外(max |C|={})".format(C_abs_max)
assert D_abs_max<=3*10**4,"Dが制約外(max |D|={})".format(D_abs_max)
#================================================
# (A,B),(C,D)の2つに分けて考える.
U=[a*b for a in A for b in B]
U.sort()
V=[c*d for c in C for d in D]
V.sort()

U_pos=[u for u in U if u>0]
U_neg=[u for u in U if u<0]

V_pos=[v for v in V if v>0]
V_neg=[v for v in V if v<0]

U_positive=len(U_pos)
U_negative=len(U_neg)
U_zero=K*L-(U_positive+U_negative)

V_positive=len(V_pos)
V_negative=len(V_neg)
V_zero=M*N-(V_positive+V_negative)

#================================================
# Eの正,ゼロ,負の個数を求める
E_positive=U_positive*V_positive+U_negative*V_negative
E_negative=U_positive*V_negative+U_negative*V_positive
E_zero=K*L*M*N-(E_positive+E_negative)

#================================================
# Jを求める.
U_abs_max=abs(max(U,key=lambda u:abs(u)))
V_abs_max=abs(max(V,key=lambda v:abs(v)))
Abs_max=U_abs_max*V_abs_max+1

if S<=E_negative: #負確定
    Ans=General_Binary_Increase_Search(-Abs_max,0,lambda x:f(x)>=S)
elif E_negative+1<=S<=E_negative+E_zero: #ゼロ確定
    Ans=0
else: #正確定
    Ans=General_Binary_Increase_Search(0,Abs_max,lambda x:g(x)>=S-(E_negative+E_zero))

#================================================
# T=abcd なる a,b,c,dを求める.
alpha,beta=h(Ans,U,V)
a,b=h(alpha,A,B)
c,d=h(beta ,C,D)

#================================================
#出力
print(Ans)
print(a,b,c,d)
0