#================================================== # 関数部 def General_Binary_Increase_Search_Integer(L, R, cond, default=None): """ 条件式が単調増加であるとき, 整数上で二部探索を行う. L: 解の下限 R: 解の上限 cond: 条件(1変数関数, 広義単調増加を満たす) default: Lで条件を満たさないときの返り値 """ if not(cond(R)): return default if cond(L): return L R+=1 while R-L>1: C=L+(R-L)//2 if cond(C): R=C else: L=C return R def move(start,direction,time): return start+direction*time def position(B,M,E,T): if E==0: M=B E=1 H=(B-M)//E F=2*B*H-E*H*H if T0: T-=(B-H*E)+M q,r=divmod(T,2*M) direction=pow(-1,H+2+q) start=pow(-1,H+1+q)*M return move(start,direction,r) else: return 0 def score_confrontation(B,M,E,mode=False): X=[[0]*N for _ in range(K)] C1=0 coef=(2*pow(10,7))/(N*(N-1)) for j in range(K): for i in range(N): X[j][i]=position(B[i], M[i], E[i], T[j]) R=0 for i in range(N): for k in range(i+1, N): R+=abs(X[j][i]-X[j][k])/(B[i]+B[k]) C1+=round(coef*R) C=round(C1/N) if mode: return C, X else: return C def score_cooperation(B,M,E,mode=False): Y=[[0]*N for _ in range(K)] C2=0 for j in range(K): for i in range(N): Y[j][i]=position(B[i],M[i],E[i],U[j]) R=max(Y[j])-min(Y[j]) C2+=round(pow(10,7)/sqrt(R/20+1)) C=round(C2/N) if mode: return C,Y else: return C def calculate(B,M,E): C1=score_confrontation(B,M,E) C2=score_cooperation(B,M,E) return C1*C2 def scoring(X,Y): C1=0 for j in range(K): R=0 for i in range(N): for k in range(i+1,N): R+=abs(X[j][i]-X[j][k])/(B[i]+B[k]) C1+=round((2*pow(10,7))/(N*(N-1))*R) C1=round(C1/N) C2=0 for j in range(N): R=max(Y[j])-min(Y[j]) C2+=round(pow(10,7)/sqrt(R/20+1)) C2=round(C2/N) return C1*C2 def debug(*message): print(*message,file=sys.stderr) #================================================== # インポート from time import * from math import sqrt from random import * import sys #================================================== # 入力 N,K=map(int,input().split()) T=list(map(int,input().split())) U=list(map(int,input().split())) #================================================== BEGIN_TIME=time() TIME_LIMIT_A=1.800 #================================================== # 初期解 best_score=-1 E=[1]*N B=[1]*N while time()-BEGIN_TIME