QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#269871#5111. Take On MemejuampiTL 12ms8564kbPython32.4kb2023-11-30 08:44:282023-11-30 08:44:29

Judging History

你现在查看的是最新测评结果

  • [2023-11-30 08:44:29]
  • 评测
  • 测评结果:TL
  • 用时:12ms
  • 内存:8564kb
  • [2023-11-30 08:44:28]
  • 提交

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)

詳細信息

Test #1:

score: 100
Accepted
time: 4ms
memory: 8564kb

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: 11ms
memory: 8532kb

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: 12ms
memory: 8500kb

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 ...

output:


result: