結果

問題 No.1319 最強とんがりコーン
ユーザー 👑 KazunKazun
提出日時 2021-07-16 18:34:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 925 ms / 2,000 ms
コード長 4,309 bytes
コンパイル時間 260 ms
コンパイル使用メモリ 87,216 KB
実行使用メモリ 78,236 KB
最終ジャッジ日時 2023-09-20 09:53:14
合計ジャッジ時間 47,840 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 917 ms
78,076 KB
testcase_01 AC 917 ms
77,416 KB
testcase_02 AC 628 ms
77,716 KB
testcase_03 AC 456 ms
78,140 KB
testcase_04 AC 917 ms
77,516 KB
testcase_05 AC 832 ms
77,700 KB
testcase_06 AC 664 ms
77,852 KB
testcase_07 AC 490 ms
77,516 KB
testcase_08 AC 686 ms
77,680 KB
testcase_09 AC 868 ms
77,572 KB
testcase_10 AC 324 ms
77,584 KB
testcase_11 AC 529 ms
77,756 KB
testcase_12 AC 721 ms
77,672 KB
testcase_13 AC 550 ms
77,720 KB
testcase_14 AC 366 ms
77,512 KB
testcase_15 AC 574 ms
77,756 KB
testcase_16 AC 383 ms
77,688 KB
testcase_17 AC 925 ms
77,556 KB
testcase_18 AC 409 ms
77,484 KB
testcase_19 AC 924 ms
77,372 KB
testcase_20 AC 920 ms
77,812 KB
testcase_21 AC 915 ms
77,572 KB
testcase_22 AC 914 ms
78,040 KB
testcase_23 AC 913 ms
77,896 KB
testcase_24 AC 920 ms
77,620 KB
testcase_25 AC 917 ms
77,512 KB
testcase_26 AC 915 ms
77,516 KB
testcase_27 AC 924 ms
78,236 KB
testcase_28 AC 917 ms
78,120 KB
testcase_29 AC 914 ms
77,920 KB
testcase_30 AC 913 ms
77,584 KB
testcase_31 AC 919 ms
78,152 KB
testcase_32 AC 657 ms
77,752 KB
testcase_33 AC 920 ms
77,620 KB
testcase_34 AC 918 ms
78,136 KB
testcase_35 AC 919 ms
77,600 KB
testcase_36 AC 917 ms
77,668 KB
testcase_37 AC 916 ms
77,540 KB
testcase_38 AC 916 ms
77,732 KB
testcase_39 AC 921 ms
77,668 KB
testcase_40 AC 532 ms
78,220 KB
testcase_41 AC 319 ms
77,720 KB
testcase_42 AC 355 ms
77,576 KB
testcase_43 AC 323 ms
77,748 KB
testcase_44 AC 361 ms
77,664 KB
testcase_45 AC 308 ms
77,716 KB
testcase_46 AC 811 ms
77,624 KB
testcase_47 AC 336 ms
77,416 KB
testcase_48 AC 534 ms
77,712 KB
testcase_49 AC 340 ms
78,028 KB
testcase_50 AC 333 ms
77,736 KB
testcase_51 AC 312 ms
77,464 KB
testcase_52 AC 326 ms
77,752 KB
testcase_53 AC 300 ms
77,572 KB
testcase_54 AC 382 ms
77,868 KB
testcase_55 AC 358 ms
77,516 KB
testcase_56 AC 320 ms
77,636 KB
testcase_57 AC 303 ms
77,568 KB
testcase_58 AC 301 ms
78,140 KB
testcase_59 AC 300 ms
77,956 KB
testcase_60 AC 202 ms
76,992 KB
testcase_61 AC 201 ms
77,112 KB
testcase_62 AC 207 ms
76,972 KB
testcase_63 AC 204 ms
77,120 KB
testcase_64 AC 675 ms
77,520 KB
testcase_65 AC 676 ms
77,576 KB
testcase_66 AC 201 ms
76,824 KB
testcase_67 AC 909 ms
77,540 KB
testcase_68 AC 903 ms
77,756 KB
testcase_69 AC 910 ms
77,640 KB
testcase_70 AC 341 ms
77,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import sqrt,sin,cos,tan,asin,acos,atan2,pi,floor

def compare(x,y,ep):
    """ x,y の大小比較をする. ただし, ep の誤差は同一視する.

    [Input]
    x,y: float
    ep: float

    [Output]
    x>y: 1
    x=y: 0
    x<y: -1
    """

    if x-y>ep: return 1
    elif x-y<-ep: return -1
    else: return 0

class Point():
    __slots__=["x","y","id"]
    ep=1e-9

    def __init__(self,x=0,y=0):
        self.x=x
        self.y=y
        self.id=0

    def sign(self,a):
        if a<-self.ep:
            return -1
        elif a>self.ep:
            return 1
        else:
            return 0

    #文字列
    def __str__(self):
        return "({}, {})".format(self.x,self.y)

    __repr__=__str__

    #Bool
    def __bool__(self):
        return self.sign(self.x)!=0 or self.sign(self.y)!=0

    #等号
    def __eq__(self,other):
        return self.sign(self.x-other.x)==0 and self.sign(self.y-other.y)==0

    #不等号
    def __ne__(self,other):
        return not self==other

    #比較(<)
    def __lt__(self,other):
        T=self.sign(self.x-other.x)
        if T:
            return T<0
        else:
            return self.sign(self.y-other.y)<0

    #比較(<=)
    def __le__(self,other):
        return self<other or self==other

    #比較(>)
    def __gt__(self,other):
        return other<self

    #比較(>=)
    def __ge__(self,other):
        return other<=self

    #正と負
    def __pos__(self):
        return self

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

    #加法
    def __add__(self,other):
        return Point(self.x+other.x,self.y+other.y)

    #減法
    def __sub__(self,other):
        return Point(self.x-other.x,self.y-other.y)

    #乗法
    def __mul__(self,other):
        x,y=self.x,self.y
        u,v=other.x,other.y
        return Point(x*u-y*v,x*v+y*u)

    def __rmul__(self,other):
        if isinstance(other,(int,float)):
            return Point(other*self.x,other*self.y)

    #除法
    def __truediv__(self,other):
        if other==0:
            raise ZeroDivisionError
        return Point(self.x/other,self.y/other)

    #絶対値
    def __abs__(self):
        return sqrt(self.x*self.x+self.y*self.y)

    norm=__abs__

    def norm_2(self):
        return self.x*self.x+self.y*self.y

    #回転
    def rotate(self,theta):
        x,y=self.x,self.y
        s,c=sin(theta),cos(theta)
        return Point(c*x-s*y,s*x+c*y)

    def __iter__(self):
        yield self.x
        yield self.y

    def __hash__(self):
        return hash((self.x,self.y))

    def latticization(self,delta=1e-7):
        if abs(self.x-floor(self.x+0.5))<delta and abs(self.y-floor(self.y+0.5))<delta:
            self.x=floor(self.x+0.5)
            self.y=floor(self.y+0.5)

    def normalization(self):
        a=abs(self)
        self.x/=a
        self.y/=a

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

    def det(self,other):
        return self.x*other.y-self.y*other.x

    def arg(self):
        return atan2(self.y,self.x)

class Circle():
    __slots__=["P","r","id"]

    ep=1e-9
    def __init__(self,Center:Point,Radius:float):
        """ 2点 P を中心とする半径 r の円を生成する.

        P: Point
        r>=0
        """
        assert Radius>=0

        self.P=Center
        self.r=Radius
        self.id=4

    def __str__(self):
        return "[Circle] Center: {}, Radius: {}".format(self.P,self.r)

    __repr__=__str__

    def __contains__(self,P):
        return abs(abs(P-self.P)-self.r)<self.ep

def Circles_Intersection_Area(C,D):
    """ 2つの円 C, D の共通部分の面積を求める.

    C, D: Circle
    """

    d=abs(C.P-D.P)
    r=C.r; s=D.r
    ep=max(C.ep, D.ep)

    if compare(d,r+s,ep)==1:
        return 0
    if compare(d,abs(r-s),ep)==-1:
        a=min(r,s)
        return pi*a*a

    alpha=acos((d*d+r*r-s*s)/(2*d*r))
    beta =acos((d*d-r*r+s*s)/(2*d*s))

    X=r*r*alpha
    Y=s*s*beta
    Z=d*r*sin(alpha)
    return X+Y-Z
#=================================================
R,H,D=map(float,input().split())

z=0
delta=H*(1e-7)
X=Circle(Point(0,0),0)
Y=Circle(Point(D,0),0)
V=0

while z<H:
    r=R*(1-(2*z+delta)/(2*H))
    X.r=Y.r=r
    V+=Circles_Intersection_Area(X,Y)*delta
    z+=delta

print(V)
0