結果

問題 No.2632 Center of Three Points in Lp Norm
ユーザー NyaanNyaanNyaanNyaan
提出日時 2024-02-16 23:49:10
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,964 ms / 2,000 ms
コード長 1,801 bytes
コンパイル時間 123 ms
コンパイル使用メモリ 12,032 KB
実行使用メモリ 67,112 KB
最終ジャッジ日時 2024-02-16 23:51:33
合計ジャッジ時間 77,457 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
外部呼び出し有り
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,855 ms
66,980 KB
testcase_01 AC 1,872 ms
67,004 KB
testcase_02 AC 1,853 ms
66,984 KB
testcase_03 AC 1,859 ms
66,972 KB
testcase_04 AC 1,870 ms
66,976 KB
testcase_05 AC 1,918 ms
66,972 KB
testcase_06 AC 1,882 ms
66,988 KB
testcase_07 AC 1,906 ms
66,980 KB
testcase_08 AC 1,890 ms
67,004 KB
testcase_09 AC 1,893 ms
66,984 KB
testcase_10 AC 1,865 ms
66,980 KB
testcase_11 AC 1,867 ms
66,996 KB
testcase_12 AC 1,863 ms
66,972 KB
testcase_13 AC 1,870 ms
67,012 KB
testcase_14 AC 1,901 ms
66,980 KB
testcase_15 AC 1,872 ms
66,988 KB
testcase_16 AC 1,858 ms
66,972 KB
testcase_17 AC 1,868 ms
66,972 KB
testcase_18 AC 1,875 ms
66,972 KB
testcase_19 AC 1,928 ms
66,972 KB
testcase_20 AC 1,861 ms
66,972 KB
testcase_21 AC 1,879 ms
66,956 KB
testcase_22 AC 1,866 ms
66,976 KB
testcase_23 AC 1,900 ms
66,972 KB
testcase_24 AC 1,872 ms
66,984 KB
testcase_25 AC 1,898 ms
66,976 KB
testcase_26 AC 1,857 ms
66,992 KB
testcase_27 AC 1,893 ms
66,976 KB
testcase_28 AC 1,885 ms
66,976 KB
testcase_29 AC 1,911 ms
66,980 KB
testcase_30 AC 1,903 ms
66,968 KB
testcase_31 AC 1,909 ms
66,968 KB
testcase_32 AC 1,910 ms
66,976 KB
testcase_33 AC 1,875 ms
66,956 KB
testcase_34 AC 1,964 ms
66,968 KB
testcase_35 AC 1,879 ms
66,972 KB
testcase_36 AC 1,941 ms
67,112 KB
testcase_37 AC 1,938 ms
67,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np
import scipy
import time
import random

p = float(input())
ax, ay = map(float, input().split())
bx, by = map(float, input().split())
cx, cy = map(float, input().split())

dx = (ax + bx + cx) / 3
dy = (ay + by + cy) / 3

def my_pow(x):
    return np.abs(x) ** p

def f(point):
    x, y = point
    anorm = my_pow(ax - x) + my_pow(ay - y)
    bnorm = my_pow(bx - x) + my_pow(by - y)
    cnorm = my_pow(cx - x) + my_pow(cy - y)
    return pow(max(anorm, bnorm, cnorm) - min(anorm, bnorm, cnorm), 1.0 / p)

def f2(point):
    x, y = point
    anorm = my_pow(ax - x) + my_pow(ay - y)
    bnorm = my_pow(bx - x) + my_pow(by - y)
    cnorm = my_pow(cx - x) + my_pow(cy - y)
    return max(anorm, bnorm, cnorm) - min(anorm, bnorm, cnorm)

start = time.time()

ans = []
best = 1e9

def check(X, Y):
    global ans, best
    cur = scipy.optimize.fmin(f, [X, Y], disp=False, maxiter=500, ftol=1e-12)
    if f(cur) < best:
        ans = cur
        best = f(cur)

def check2(X, Y):
    global ans, best
    cur = scipy.optimize.fmin(f2, [X, Y], disp=False, maxiter=500, ftol=1e-12)
    if f(cur) < best:
        ans = cur
        best = f(cur)

for scale in range(5, 7):
    for X in [-(10**scale), 10**scale]:
        for Y in [-(10**scale), 10**scale]:
            if time.time() - start < 1.3:
#                check(X, Y)
                check(X + dx, Y + dy)

for scale in range(5, 7):
    for X in [-(10**scale), 10**scale]:
        for Y in [-(10**scale), 10**scale]:
            if time.time() - start < 1.3:
                check2(X + dx, Y + dy)

while time.time() - start < 1.3:
    scale = random.randint(1, 6)
    X = random.randint(-(10**scale), 10**scale) 
    Y = random.randint(-(10**scale), 10**scale)
    check(X + dx, Y + dy)

print("{:.10f} {:.10f}".format(ans[0], ans[1]))
0