結果
問題 | No.2008 Super Worker |
ユーザー |
👑 ![]() |
提出日時 | 2022-04-27 01:24:20 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,348 ms / 2,000 ms |
コード長 | 5,141 bytes |
コンパイル時間 | 251 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 133,284 KB |
最終ジャッジ日時 | 2024-06-28 07:34:12 |
合計ジャッジ時間 | 17,729 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 33 |
ソースコード
from math import gcdclass Fraction():reduction=0__slots__=("a","b")##入力定義def __init__(self, Numerator=0, Denominator=1, reduction=True, expanded=False):"""分数のオブジェクトを生成する.Numerator: 分子Denominator: 分母 (!=0)"""assert Denominator or expanded,"分母が0"if Denominator<0:Numerator*=-1Denominator*=-1self.a=Numeratorself.b=Denominatorif reduction:g=gcd(Numerator, Denominator)self.a=Numerator//gself.b=Denominator//g#表示定義def __str__(self):if self.b==1:return str(self.a)else:return "{}/{}".format(self.a,self.b)__repr__=__str__#四則演算定義def __add__(self,other):if other.__class__==Fraction:x=self.a*other.b+self.b*other.ay=self.b*other.belif other.__class__==int:x=self.a+self.b*othery=self.belse:assert 0,"型が違う"return Fraction(x,y)def __radd__(self,other):return self+otherdef __sub__(self,other):if other.__class__==Fraction:x=self.a*other.b-self.b*other.ay=self.b*other.belif other.__class__==int:x=self.a-self.b*othery=self.belse:assert 0,"型が違う"return Fraction(x,y)def __rsub__(self,other):return -self+otherdef __mul__(self,other):if other.__class__==Fraction:x=self.a*other.ay=self.b*other.belif other.__class__==int:x=self.a*othery=self.belse:assert 0,"型が違う"return Fraction(x,y)def __rmul__(self,other):return self*otherdef __floordiv__(self,other):if other==Fraction():raise ZeroDivisionErrorH=self/otherreturn H.a//H.bdef __rfloordiv__(self,other):if self==Fraction():raise ZeroDivisionErrorH=other/selfreturn H.a//H.bdef __truediv__(self,other):assert other,"除数が0"if other.__class__==Fraction:x=self.a*other.by=self.b*other.aelif other.__class__==int:x=self.ay=self.b*otherelse:assert 0,"型が違う"return Fraction(x,y)def __rtruediv__(self,other):assert self,"除数が0"if other.__class__==Fraction:x=other.a*self.by=other.b*self.aelif other.__class__==int:x=other*self.by=self.aelse:assert 0,"型が違う"return Fraction(x,y)def __pow__(self,m):alpha,beta=self.a,self.bif m<0:alpha,beta=beta,alpham=-mreturn Fraction(pow(alpha,m),pow(beta,m))#丸めdef __floor__(self):return self.a//self.bdef __ceil__(self):return (self.a+self.b-1)//self.b#真偽値def __bool__(self):return bool(self.a)#比較def __eq__(self,other):if other.__class__==Fraction:return self.a*other.b==self.b*other.aelif other.__class__==int:return self.a==self.b*otherelse:assert 0,"型が違う"def __nq__(self,other):return not(self==other)def __lt__(self,other):return self<=other and self!=otherdef __le__(self,other):if other.__class__==Fraction:return self.a*other.b<=self.b*other.aelif other.__class__==int:return self.a<=self.b*otherelse:assert 0,"型が違う"def __gt__(self,other):return other<=self and other!=selfdef __ge__(self,other):return other<=self#その他def __float__(self):return self.a/self.bdef sign(self):s=self.a*self.bif s>0:return 1elif s==0:return 0else:return -1#符号def __pos__(self):return selfdef __neg__(self):return Fraction(-self.a,self.b)def __abs__(self):if self.a>0:return selfelse:return -self#その他def is_unit(self):return self.a==1def __hash__(self):return hash(10**9*self.a+self.b)#==================================================from operator import itemgetterN=int(input())A=list(map(int,input().split()))B=list(map(int,input().split()))W=[(i,Fraction(b-1,a,False)) for i,(a,b) in enumerate(zip(A,B))]W.sort(key=itemgetter(1),reverse=True)Ans=0; Mod=10**9+7Level=1;for i,_ in W:Ans+=A[i]*Level; Ans%=ModLevel*=B[i]; Level%=Modprint(Ans)