結果

問題 No.764 浮動点
ユーザー mkawa2mkawa2
提出日時 2022-02-05 11:27:30
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 52 ms / 1,500 ms
コード長 3,493 bytes
コンパイル時間 110 ms
コンパイル使用メモリ 13,184 KB
実行使用メモリ 11,520 KB
最終ジャッジ日時 2024-06-11 13:24:54
合計ジャッジ時間 2,419 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
11,264 KB
testcase_01 AC 32 ms
11,392 KB
testcase_02 AC 33 ms
11,392 KB
testcase_03 AC 38 ms
11,264 KB
testcase_04 AC 47 ms
11,136 KB
testcase_05 AC 37 ms
11,392 KB
testcase_06 AC 46 ms
11,520 KB
testcase_07 AC 39 ms
11,392 KB
testcase_08 AC 47 ms
11,264 KB
testcase_09 AC 40 ms
11,392 KB
testcase_10 AC 50 ms
11,264 KB
testcase_11 AC 40 ms
11,520 KB
testcase_12 AC 50 ms
11,264 KB
testcase_13 AC 51 ms
11,264 KB
testcase_14 AC 51 ms
11,392 KB
testcase_15 AC 51 ms
11,392 KB
testcase_16 AC 51 ms
11,264 KB
testcase_17 AC 51 ms
11,392 KB
testcase_18 AC 49 ms
11,136 KB
testcase_19 AC 48 ms
11,264 KB
testcase_20 AC 52 ms
11,392 KB
testcase_21 AC 51 ms
11,392 KB
testcase_22 AC 51 ms
11,392 KB
testcase_23 AC 49 ms
11,264 KB
testcase_24 AC 52 ms
11,392 KB
testcase_25 AC 33 ms
11,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
# inf = (1 << 63)-1
inf = (1 << 31)-1
# md = 10**9+7
md = 998244353

from math import *

# init_x, init_yは始線
class Vector:
    def __init__(self, x, y, init_x=1, init_y=0):
        self.x = x
        self.y = y
        self.norm2 = x*x+y*y
        self.norm = self.norm2**0.5
        self.zone = 2
        if x == y == 0: self.zone = -1
        elif init_x*y-init_y*x > 0: self.zone = 1
        elif init_x*y-init_y*x < 0: self.zone = 3
        elif init_x*x+init_y*y > 0: self.zone = 0

    def __repr__(self):
        return "({},{})".format(self.x, self.y)

    def __eq__(self, other):
        if self.zone != other.zone: return False
        return self.outer(other) == 0

    def __lt__(self, other):
        if self.zone == other.zone: return self.outer(other) > 0
        return self.zone < other.zone

    def __add__(self, other): return Vector(self.x+other.x, self.y+other.y)

    def __sub__(self, other): return Vector(self.x-other.x, self.y-other.y)

    def __iadd__(self, other):
        self.x += other.x
        self.y += other.y
        return self

    def __isub__(self, other):
        self.x -= other.x
        self.y -= other.y
        return self

    def __neg__(self):
        return Vector(-self.x, -self.y)

    def __mul__(self, val):
        return Vector(val*self.x, val*self.y)

    __rmul__ = __mul__

    def __truediv__(self, val):
        assert val != 0
        return Vector(self.x/val, self.y/val)

    def dot(self, v): return self.x*v.x+self.y*v.y

    def outer(self, v): return self.x*v.y-self.y*v.x

    def rot90(self): return Vector(-self.y, self.x)

# Circle(r,Vector) or Circle(r,x,y)
class Circle:
    def __init__(self, r, vx, oy=None):
        if not isinstance(vx, Vector): vx = Vector(vx, oy)
        self.o, self.r = vx, r

def common_part(c1, c2):
    if c1.r < c2.r: c1, c2 = c2, c1
    r1, o1 = c1.r, c1.o
    r2, o2 = c2.r, c2.o
    d = (o2-o1).norm
    d2 = (o2-o1).norm2
    if d >= r1+r2: return 0
    if r1 >= r2+d: return r2*r2*pi
    rad1 = acos((r1**2+d2-r2**2)/2/r1/d)
    rad2 = acos((r2**2+d2-r1**2)/2/r2/d)
    return r1*r1*(rad1-sin(rad1*2)/2)+r2*r2*(rad2-sin(rad2*2)/2)

def radius(ll):
    aa = [0]*(len(ll)-1)
    bb = [0]*(len(ll)-1)
    s = m = 0
    for i, l in enumerate(ll[:-1]):
        s += l
        m = max(m, l)
        aa[i] = s
        bb[i] = max(0, 2*m-s)
    return aa, bb

n = II()
x = II()
ll = [II() for _ in range(n+1)]

aa, bb = radius(ll)
pp, qq = radius(ll[::-1])
pp.reverse()
qq.reverse()
# pDB(aa)
# pDB(bb)
# pDB(pp)
# pDB(qq)

for a, b, p, q in zip(aa, bb, pp, qq):
    if a == b or p == q:
        print(0)
        continue
    l1 = Circle(a, 0, 0)
    l2 = Circle(b, 0, 0)
    r1 = Circle(p, x, 0)
    r2 = Circle(q, x, 0)
    ans = common_part(l1, r1)-common_part(l1, r2)-common_part(l2, r1)+common_part(l2, r2)
    print(ans)
0