結果
問題 | No.1361 [Zelkova 4th Tune *] QUADRUPLE-SEQUENCEの詩 |
ユーザー |
👑 ![]() |
提出日時 | 2021-01-22 02:04:47 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 921 ms / 2,000 ms |
コード長 | 3,328 bytes |
コンパイル時間 | 570 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 181,376 KB |
最終ジャッジ日時 | 2024-12-27 18:40:16 |
合計ジャッジ時間 | 27,001 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 74 |
ソースコード
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 Falseif Integer:R+=1while R-L>1:C=L+(R-L)//2if cond(C):R=Celse:L=Creturn Relse:while (R-L)>=ep:C=L+(R-L)/2if cond(C):R=Celse:L=Creturn R#================================================def f(x): #負の時の判定Z=0I=0for u in U_pos:while (I<V_negative and u*V_neg[I]<=x):I+=1Z+=II=0for v in V_pos:while (I<U_negative and v*U_neg[I]<=x):I+=1Z+=Ireturn Zdef g(x): #正の時の判定Z=0I=V_positivefor u in U_pos:while (I>0 and u*V_pos[I-1]>x):I-=1Z+=II=0for v in V_neg:while (I<U_negative and v*U_neg[-(I+1)]<=x):I+=1Z+=Ireturn 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:continueif (x%g==0) and (x//g in H):return (g,x//g)return None#================================================#入力import sysinput=sys.stdin.readlineK,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_negativeE_negative=U_positive*V_negative+U_negative*V_positiveE_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+1if 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=0else: #正確定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)