QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#268144 | #5111. Take On Meme | juampi | TL | 9ms | 8564kb | Python3 | 2.4kb | 2023-11-28 09:49:39 | 2023-11-28 09:49:39 |
Judging History
answer
import random
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def __neg__(self):
return Point(-self.x, -self.y)
def __add__(self, p):
return Point(self.x + p.x, self.y + p.y)
def __sub__(self, p):
return Point(self.x - p.x, self.y - p.y)
def add2(self, p):
self.x += p.x
self.y += p.y
def __lt__(self, p):
return self.x * cmpx + self.y * cmpy < p.x * cmpx + p.y * cmpy
def __gt__(self, p):
return self.x * cmpx + self.y * cmpy > p.x * cmpx + p.y * cmpy
def __eq__(self, p):
return self.x == p.x and self.y == p.y
def ortho(self):
return Point(-self.y, self.x)
def lensqr(self):
return self.x * self.x + self.y * self.y
def print(self):
print("(",self.x,",",self.y,")")
def init():
random.seed()
global cmpx, cmpy, ch, p, ret
cmpx = 1
cmpy = 0
ret = 0
def doit(x):
if len(ch[x]) == 0:
return (p[x], p[x])
result = doit(ch[x][0])
mntot = result[0]
mxtot = result[1]
mndiff = mxtot + mntot
mxdiff = mndiff
for i in range(1, len(ch[x])):
result = doit(ch[x][i])
mn = result[0]
mx = result[1]
mntot = mntot + mn
mxtot = mxtot + mx
mndiff = min(mndiff, mx + mn)
mxdiff = max(mxdiff, mx + mn)
return (-mxtot + mndiff, -mntot + mxdiff)
def tryAngle(dir):
global cmpx, cmpy, ret # Add 'ret' to the list of global variables
cmpx = dir.x
cmpy = dir.y
result = doit(1)
mn = result[0]
mx = result[1]
ret = max(ret, mn.lensqr())
ret = max(ret, mx.lensqr())
return (mn, mx)
def traceHull(a, b):
if a == b:
return
result = tryAngle((b-a).ortho())
c = result[1]
if a < c:
traceHull(a, c)
traceHull(c, b)
init()
N = int(input())
ch = [[] for _ in range(N + 1)]
p = [None] * (N + 1)
for i in range(1, N + 1):
line = input().split()
M = int(line[0])
if M == 0:
x = int(line[1])
y = int(line[2])
p[i] = Point(x, y)
else:
ch[i] = list(map(int, line[1:]))
ret = 0
angles = tryAngle(Point(1, 0))
left = angles[0]
right = angles[1]
traceHull(left, right)
traceHull(right, left)
print(ret)
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 7ms
memory: 8412kb
input:
5 4 2 3 4 5 0 2 -2 0 1 3 0 4 -6 0 -18 5
output:
725
result:
ok single line: '725'
Test #2:
score: 0
Accepted
time: 3ms
memory: 8536kb
input:
5 2 2 3 2 4 5 0 1 5 0 -4 -6 0 -1 7
output:
340
result:
ok single line: '340'
Test #3:
score: 0
Accepted
time: 9ms
memory: 8564kb
input:
18 3 4 3 2 2 5 6 3 7 9 8 3 10 11 12 0 4 -1 0 18 49 0 -2 10 2 13 14 0 -5 6 0 5 8 4 15 16 17 18 0 17 3 0 3 -9 0 -7 -1 0 14 -33 0 -23 11 0 11 14 0 2 19
output:
26269
result:
ok single line: '26269'
Test #4:
score: -100
Time Limit Exceeded
input:
10000 59 2 171 340 509 678 847 1016 1185 1382 1551 1720 1889 2058 2227 2396 2565 2734 2903 3072 3241 3410 3579 3748 3917 4086 4255 4424 4593 4762 4931 5100 5269 5438 5607 5776 5945 6114 6283 6452 6621 6790 6959 7128 7297 7466 7635 7804 7973 8142 8311 8480 8649 8818 8987 9156 9325 9494 9663 9832 2 3 ...