QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#543134 | #8677. Carl’s Vacation | qwerasdf | WA | 15ms | 10840kb | Python3 | 2.4kb | 2024-09-01 14:17:20 | 2024-09-01 14:17:20 |
Judging History
answer
import math
def rot90(a): # 반시계
return (-a[1], a[0])
def dot(a, b):
return a[0] * b[0] + a[1] * b[1]
def cross(a, b):
return a[0] * b[1] - a[1] * b[0]
def add(a, b):
return (a[0] + b[0], a[1] + b[1])
def sub(a, b):
return (a[0] - b[0], a[1] - b[1])
def mul(a, b): # a: 스칼라
return (a * b[0], a * b[1])
def dist(a, b):
t = sub(b, a)
return math.sqrt(dot(t, t))
def is_facing(a, b, c, d):
n0 = rot90(sub(a, b))
n1 = rot90(sub(c, d))
return dot(n0, sub(c, a)) >= 0 and dot(n0, sub(d, a)) >= 0 and dot(n1, sub(a, c)) >= 0 and dot(n1, sub(b, c)) >= 0
def make_tri(a, b, h):
norm = rot90(sub(b, a))
sq = dot(norm, norm)
k = math.sqrt((math.sqrt(sq) / 2) ** 2 + h ** 2)
c = add(mul(k / math.sqrt(sq), norm), mul(0.5, add(a, b)))
return (a, b, c)
def is_in(p, a, b, x):
v0 = sub(a, p)
v1 = sub(x, p)
v2 = sub(b, p)
return cross(v0, v1) >= 0 and cross(v1, v2) >= 0
ls = []
for i in range(2):
ls.append([*map(int, input().split())])
pyra = []
tmp = []
for l in ls:
x = l[0]
y = l[1]
dx = l[2] - x
dy = l[3] - y
tmp = [(x, y), (x + dx, y + dy), (x + dx - dy, y + dy + dx), (x - dy, y + dx), l[4]]
pyra.append(tmp)
for i in range(4):
for j in range(4):
a = pyra[0][i % 4]
b = pyra[0][(i + 1) % 4]
c = pyra[1][j % 4]
d = pyra[1][(j + 1) % 4]
if is_facing(a, b, c, d):
t0 = make_tri(a, b, pyra[0][4])
t1 = make_tri(c, d, pyra[1][4])
#print(t0, t1)
a, b, c = t0
d, e, f = t1
mn = 1e9
# case work
if is_in(c, a, b, f) and is_in(f, d, e, c):
mn = min(mn, dist(c, f))
#print('cf')
if is_in(c, a, b, d):
mn = min(mn, dist(c, d) + dist(d, f))
#print('cdf')
if is_in(c, a, b, e):
mn = min(mn, dist(c, e) + dist(e, f))
#print('cef')
if is_in(f, d, e, a):
mn = min(mn, dist(c, a) + dist(a, f))
#print('caf')
if is_in(f, d, e, b):
mn = min(mn, dist(c, b) + dist(b, f))
#print('cbf')
mn = min(mn, dist(c, a) + dist(f, d) + min([dist(a, d), dist(a, e), dist(b, d), dist(b, e)]))
print(mn)
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 15ms
memory: 10788kb
input:
1 0 0 0 10000 99999 10000 10000 10000 10000
output:
76118.70004922048
result:
ok found '76118.7000492', expected '76118.7000492', error '0.0000000'
Test #2:
score: -100
Wrong Answer
time: 7ms
memory: 10840kb
input:
10000 10000 10000 0 10000 0 0 0 10000 10000
output:
34494.89742783178
result:
wrong answer 1st numbers differ - expected: '32360.6797750', found: '34494.8974278', error = '0.0659510'