import sys from time import time from random import random, randrange, choice, choices from heapq import heappop, heappush from math import exp START = time() INF=10**9 def get_time(START): return time() - START def dist(p1,p2): x1,y1=p1 x2,y2=p2 return (x1-x2)**2 + (y1-y2)**2 def calc(i: int, j: int): d = dist(Terminals[ans[i]], Terminals[ans[j]]) if ans[i]0: best_score = current_score #print("swap",current_score, file=sys.stderr) else: ans[v1],ans[v2] = ans[v2],ans[v1] else: v = randrange(N,N+M) original = Terminals[v][:] best_i = -1 sub_best_score = best_score for i in range(8): Terminals[v][0] = original[0]+dx[i] Terminals[v][1] = original[1]+dy[i] current_score = calc_score(ans) if current_score < sub_best_score: sub_best_score = current_score best_i = i if best_i != -1: best_score = sub_best_score Terminals[v][0] = original[0]+dx[best_i] Terminals[v][1] = original[1]+dy[best_i] #print("move",best_score, file=sys.stderr) else: Terminals[v]=original[:] # アウトプット for pos in Terminals[N:]: print(*pos) print(len(ans)) for v in ans: if v