結果

問題 No.1361 [Zelkova 4th Tune *] QUADRUPLE-SEQUENCEの詩
ユーザー 👑 KazunKazun
提出日時 2020-11-01 18:05:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 918 ms / 2,000 ms
コード長 3,291 bytes
コンパイル時間 465 ms
コンパイル使用メモリ 87,208 KB
実行使用メモリ 182,720 KB
最終ジャッジ日時 2023-08-27 16:17:01
合計ジャッジ時間 33,031 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
71,388 KB
testcase_01 AC 79 ms
71,332 KB
testcase_02 AC 81 ms
71,456 KB
testcase_03 AC 80 ms
71,500 KB
testcase_04 AC 79 ms
71,272 KB
testcase_05 AC 81 ms
71,388 KB
testcase_06 AC 82 ms
71,432 KB
testcase_07 AC 80 ms
71,332 KB
testcase_08 AC 101 ms
76,192 KB
testcase_09 AC 96 ms
76,060 KB
testcase_10 AC 100 ms
75,840 KB
testcase_11 AC 100 ms
76,016 KB
testcase_12 AC 99 ms
75,812 KB
testcase_13 AC 98 ms
76,096 KB
testcase_14 AC 95 ms
75,544 KB
testcase_15 AC 107 ms
76,316 KB
testcase_16 AC 100 ms
76,000 KB
testcase_17 AC 96 ms
76,068 KB
testcase_18 AC 146 ms
78,896 KB
testcase_19 AC 124 ms
77,220 KB
testcase_20 AC 137 ms
78,192 KB
testcase_21 AC 122 ms
78,280 KB
testcase_22 AC 131 ms
78,516 KB
testcase_23 AC 145 ms
79,460 KB
testcase_24 AC 144 ms
80,368 KB
testcase_25 AC 144 ms
79,472 KB
testcase_26 AC 147 ms
79,408 KB
testcase_27 AC 127 ms
77,624 KB
testcase_28 AC 416 ms
110,544 KB
testcase_29 AC 360 ms
104,524 KB
testcase_30 AC 347 ms
99,704 KB
testcase_31 AC 433 ms
110,476 KB
testcase_32 AC 561 ms
134,104 KB
testcase_33 AC 337 ms
98,656 KB
testcase_34 AC 463 ms
120,688 KB
testcase_35 AC 457 ms
114,324 KB
testcase_36 AC 694 ms
137,212 KB
testcase_37 AC 269 ms
98,452 KB
testcase_38 AC 365 ms
109,684 KB
testcase_39 AC 292 ms
95,316 KB
testcase_40 AC 324 ms
103,144 KB
testcase_41 AC 483 ms
115,000 KB
testcase_42 AC 677 ms
135,436 KB
testcase_43 AC 437 ms
111,056 KB
testcase_44 AC 530 ms
117,792 KB
testcase_45 AC 385 ms
111,992 KB
testcase_46 AC 546 ms
124,464 KB
testcase_47 AC 337 ms
99,324 KB
testcase_48 AC 655 ms
182,648 KB
testcase_49 AC 428 ms
182,636 KB
testcase_50 AC 634 ms
182,596 KB
testcase_51 AC 531 ms
182,644 KB
testcase_52 AC 647 ms
182,720 KB
testcase_53 AC 918 ms
156,800 KB
testcase_54 AC 899 ms
156,632 KB
testcase_55 AC 894 ms
156,696 KB
testcase_56 AC 892 ms
156,744 KB
testcase_57 AC 728 ms
156,792 KB
testcase_58 AC 617 ms
153,692 KB
testcase_59 AC 612 ms
153,828 KB
testcase_60 AC 501 ms
153,884 KB
testcase_61 AC 502 ms
153,636 KB
testcase_62 AC 506 ms
153,892 KB
testcase_63 AC 135 ms
127,092 KB
testcase_64 AC 137 ms
126,924 KB
testcase_65 AC 138 ms
126,952 KB
testcase_66 AC 136 ms
126,824 KB
testcase_67 AC 138 ms
127,000 KB
testcase_68 AC 77 ms
71,276 KB
testcase_69 AC 78 ms
71,288 KB
testcase_70 AC 78 ms
71,324 KB
testcase_71 AC 76 ms
71,308 KB
testcase_72 AC 79 ms
71,116 KB
testcase_73 AC 76 ms
71,368 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()))
#================================================
# (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