結果
問題 | No.907 Continuous Kadomatu |
ユーザー | vwxyz |
提出日時 | 2024-05-03 23:03:28 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 5,507 bytes |
コンパイル時間 | 174 ms |
コンパイル使用メモリ | 82,360 KB |
実行使用メモリ | 156,148 KB |
最終ジャッジ日時 | 2024-11-25 04:32:40 |
合計ジャッジ時間 | 30,048 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
61,716 KB |
testcase_01 | AC | 40 ms
132,660 KB |
testcase_02 | AC | 36 ms
60,192 KB |
testcase_03 | AC | 38 ms
132,064 KB |
testcase_04 | AC | 38 ms
60,912 KB |
testcase_05 | AC | 204 ms
155,772 KB |
testcase_06 | AC | 99 ms
83,152 KB |
testcase_07 | AC | 130 ms
156,148 KB |
testcase_08 | AC | 552 ms
84,396 KB |
testcase_09 | AC | 163 ms
155,784 KB |
testcase_10 | AC | 1,249 ms
84,748 KB |
testcase_11 | AC | 1,955 ms
155,748 KB |
testcase_12 | TLE | - |
testcase_13 | TLE | - |
testcase_14 | TLE | - |
testcase_15 | AC | 816 ms
79,148 KB |
testcase_16 | AC | 836 ms
79,164 KB |
testcase_17 | TLE | - |
testcase_18 | TLE | - |
testcase_19 | TLE | - |
testcase_20 | AC | 97 ms
74,552 KB |
testcase_21 | AC | 115 ms
76,348 KB |
testcase_22 | AC | 116 ms
76,044 KB |
testcase_23 | AC | 1,108 ms
78,608 KB |
testcase_24 | TLE | - |
testcase_25 | AC | 37 ms
54,144 KB |
testcase_26 | AC | 37 ms
54,860 KB |
testcase_27 | AC | 37 ms
54,160 KB |
testcase_28 | AC | 37 ms
53,468 KB |
testcase_29 | AC | 41 ms
134,372 KB |
ソースコード
def Compress(lst): decomp=sorted(list(set(lst))) comp={x:i for i,x in enumerate(decomp)} return comp,decomp def Extended_Euclid(n,m): stack=[] while m: stack.append((n,m)) n,m=m,n%m if n>=0: x,y=1,0 else: x,y=-1,0 for i in range(len(stack)-1,-1,-1): n,m=stack[i] x,y=y,x-(n//m)*y return x,y class MOD: def __init__(self,p,e=None): self.p=p self.e=e if self.e==None: self.mod=self.p else: self.mod=self.p**self.e def Pow(self,a,n): a%=self.mod if n>=0: return pow(a,n,self.mod) else: #assert math.gcd(a,self.mod)==1 x=Extended_Euclid(a,self.mod)[0] return pow(x,-n,self.mod) def Build_Fact(self,N): assert N>=0 self.factorial=[1] if self.e==None: for i in range(1,N+1): self.factorial.append(self.factorial[-1]*i%self.mod) else: self.cnt=[0]*(N+1) for i in range(1,N+1): self.cnt[i]=self.cnt[i-1] ii=i while ii%self.p==0: ii//=self.p self.cnt[i]+=1 self.factorial.append(self.factorial[-1]*ii%self.mod) self.factorial_inve=[None]*(N+1) self.factorial_inve[-1]=self.Pow(self.factorial[-1],-1) for i in range(N-1,-1,-1): ii=i+1 while ii%self.p==0: ii//=self.p self.factorial_inve[i]=(self.factorial_inve[i+1]*ii)%self.mod def Build_Inverse(self,N): self.inverse=[None]*(N+1) assert self.p>N self.inverse[1]=1 for n in range(2,N+1): if n%self.p==0: continue a,b=divmod(self.mod,n) self.inverse[n]=(-a*self.inverse[b])%self.mod def Inverse(self,n): return self.inverse[n] def Fact(self,N): if N<0: return 0 retu=self.factorial[N] if self.e!=None and self.cnt[N]: retu*=pow(self.p,self.cnt[N],self.mod)%self.mod retu%=self.mod return retu def Fact_Inve(self,N): if self.e!=None and self.cnt[N]: return None return self.factorial_inve[N] def Comb(self,N,K,divisible_count=False): if K<0 or K>N: return 0 retu=self.factorial[N]*self.factorial_inve[K]%self.mod*self.factorial_inve[N-K]%self.mod if self.e!=None: cnt=self.cnt[N]-self.cnt[N-K]-self.cnt[K] if divisible_count: return retu,cnt else: retu*=pow(self.p,cnt,self.mod) retu%=self.mod return retu class Cumsum: def __init__(self,lst,mod=0): self.N=len(lst) self.mod=mod self.cumsum=[0]*(self.N+1) self.cumsum[0]=0 for i in range(1,self.N+1): self.cumsum[i]=self.cumsum[i-1]+lst[i-1] if self.mod: self.cumsum[i]%=self.mod def __getitem__(self,i): if type(i)==int: if 0<=i<self.N: a,b=i,i+1 elif -self.N<=i<0: a,b=i+self.N,i+self.N+1 else: raise IndexError('list index out of range') else: a,b=i.start,i.stop if a==None or a<-self.N: a=0 elif self.N<=a: a=self.N elif a<0: a+=self.N if b==None or self.N<=b: b=self.N elif b<-self.N: b=0 elif b<0: b+=self.N s=self.cumsum[b]-self.cumsum[a] if self.mod: s%=self.mod return s def __setitem__(self,i,x): if -self.N<=i<0: i+=self.N elif not 0<=i<self.N: raise IndexError('list index out of range') self.cumsum[i+1]=self.cumsum[i]+x if self.mod: self.cumsum[i+1]%=self.mod def __len__(self): return self.N def __str__(self): lst=[self.cumsum[i+1]-self.cumsum[i] for i in range(self.N)] if self.mod: for i in range(self.N): lst[i]%=self.mod return "["+", ".join(map(str,lst))+"]" N=int(input()) A,B=[],[] for i in range(N): a,b=map(int,input().split()) A.append(a) B.append(b) mod=10**9+7 MD=MOD(mod) MD.Build_Fact(N) dp=[1] cnt=[1] for le in range(1,N+1): cnt.append(sum(dp)%mod) prev=dp dp=[0]*(1+le) for i in range(le): for j in range(le+1): if le%2 and j<=i or le%2==0 and i<j: dp[j]+=prev[i] dp[j]%=mod inf=1<<30 comp,decomp=Compress(A+B+[inf]) le=len(comp)-1 dp=[[0]*le for i in range(N+1)] dp[0][le-1]=1 dp[0]=Cumsum(dp[0],mod=mod) BA=[b-a for a,b in zip(A,B)] BA_inve=[MD.Pow(b-a,-1) for a,b in zip(A,B)] for r in range(1,N+1): for x in range(le-1): p=1 for l in range(r-1,-1,-1): d=decomp[x+1]-decomp[x] if max(decomp[x],A[l])<min(decomp[x+1],B[l]): p*=BA_inve[l]*d p%=mod else: p=0 if l%2: dp[r][x]+=dp[l][:x]*cnt[r-l]*MD.Fact_Inve(r-l)*p%mod else: dp[r][x]+=dp[l][x+1:]*cnt[r-l]*MD.Fact_Inve(r-l)*p%mod dp[r][x]%=mod dp[r]=Cumsum(dp[r],mod=mod) ans=dp[-1][:] print(ans)