結果

問題 No.916 Encounter On A Tree
ユーザー vwxyzvwxyz
提出日時 2024-04-18 13:16:56
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 3,093 bytes
コンパイル時間 219 ms
コンパイル使用メモリ 82,516 KB
実行使用メモリ 173,696 KB
最終ジャッジ日時 2024-04-18 13:17:11
合計ジャッジ時間 8,169 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 37 ms
53,504 KB
testcase_02 AC 188 ms
173,312 KB
testcase_03 AC 180 ms
173,568 KB
testcase_04 AC 180 ms
173,184 KB
testcase_05 AC 178 ms
173,184 KB
testcase_06 WA -
testcase_07 AC 179 ms
173,440 KB
testcase_08 AC 56 ms
71,552 KB
testcase_09 AC 72 ms
84,480 KB
testcase_10 AC 36 ms
52,608 KB
testcase_11 AC 36 ms
53,120 KB
testcase_12 AC 184 ms
173,696 KB
testcase_13 AC 176 ms
173,696 KB
testcase_14 AC 179 ms
173,388 KB
testcase_15 AC 179 ms
173,312 KB
testcase_16 AC 72 ms
84,224 KB
testcase_17 AC 180 ms
173,568 KB
testcase_18 AC 38 ms
52,608 KB
testcase_19 AC 178 ms
173,460 KB
testcase_20 WA -
testcase_21 AC 184 ms
173,568 KB
testcase_22 AC 181 ms
173,184 KB
testcase_23 AC 180 ms
173,504 KB
testcase_24 AC 178 ms
173,672 KB
testcase_25 AC 180 ms
173,568 KB
testcase_26 AC 102 ms
110,208 KB
testcase_27 AC 101 ms
109,440 KB
testcase_28 AC 72 ms
83,840 KB
testcase_29 AC 183 ms
173,568 KB
testcase_30 AC 176 ms
173,568 KB
testcase_31 AC 182 ms
173,568 KB
testcase_32 AC 182 ms
173,184 KB
testcase_33 AC 101 ms
109,824 KB
testcase_34 AC 77 ms
83,840 KB
testcase_35 AC 56 ms
71,680 KB
testcase_36 AC 181 ms
173,568 KB
testcase_37 AC 180 ms
173,184 KB
testcase_38 AC 73 ms
84,096 KB
testcase_39 AC 186 ms
173,616 KB
testcase_40 AC 180 ms
173,184 KB
testcase_41 AC 36 ms
52,864 KB
testcase_42 AC 37 ms
52,480 KB
testcase_43 AC 38 ms
52,736 KB
testcase_44 AC 40 ms
52,864 KB
testcase_45 AC 58 ms
71,296 KB
testcase_46 AC 39 ms
53,120 KB
testcase_47 AC 38 ms
52,864 KB
testcase_48 AC 37 ms
52,864 KB
testcase_49 AC 36 ms
52,480 KB
testcase_50 AC 36 ms
53,120 KB
testcase_51 AC 39 ms
52,992 KB
testcase_52 AC 37 ms
52,864 KB
testcase_53 AC 37 ms
52,864 KB
testcase_54 AC 37 ms
53,248 KB
testcase_55 AC 40 ms
52,992 KB
testcase_56 AC 41 ms
58,880 KB
testcase_57 AC 41 ms
59,520 KB
testcase_58 AC 42 ms
60,160 KB
testcase_59 AC 43 ms
60,416 KB
testcase_60 AC 44 ms
62,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

D,L,R,K=map(int,input().split())
ans=0
mod=10**9+7
MD=MOD(mod)
MD.Build_Fact(1<<D)
cnt=[1<<d for d in range(D)]
l=L.bit_length()-1
r=R.bit_length()-1
if l+r<K or (l+r)%2!=K%2:
    ans=0
else:
    x=(l+r-K)//2
    cnt[l]-=1
    cnt[r]-=1
    ans=pow(2,x,mod)
    if x<l:
        ans*=pow(2,l-x-1,mod)
    if x<r:
        ans*=pow(2,r-x-1,mod)
    ans*=2
    ans%=mod
    for c in cnt:
        ans*=MD.Fact(c)
        ans%=mod
print(ans)
0