結果

問題 No.1706 Many Bus Stops (hard)
ユーザー harurunharurun
提出日時 2021-09-10 22:50:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 2,235 bytes
コンパイル時間 271 ms
コンパイル使用メモリ 87,252 KB
実行使用メモリ 76,556 KB
最終ジャッジ日時 2023-09-30 09:28:37
合計ジャッジ時間 5,566 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,100 KB
testcase_01 AC 73 ms
71,288 KB
testcase_02 AC 81 ms
76,320 KB
testcase_03 AC 84 ms
76,132 KB
testcase_04 AC 81 ms
76,360 KB
testcase_05 AC 82 ms
76,028 KB
testcase_06 AC 81 ms
76,324 KB
testcase_07 AC 83 ms
76,424 KB
testcase_08 AC 81 ms
76,424 KB
testcase_09 AC 81 ms
76,144 KB
testcase_10 AC 81 ms
76,384 KB
testcase_11 AC 83 ms
76,300 KB
testcase_12 AC 82 ms
76,364 KB
testcase_13 AC 81 ms
76,384 KB
testcase_14 AC 82 ms
76,296 KB
testcase_15 AC 82 ms
76,460 KB
testcase_16 AC 81 ms
76,456 KB
testcase_17 AC 81 ms
76,424 KB
testcase_18 AC 83 ms
76,452 KB
testcase_19 AC 81 ms
76,372 KB
testcase_20 AC 81 ms
76,396 KB
testcase_21 AC 80 ms
76,028 KB
testcase_22 AC 81 ms
76,404 KB
testcase_23 AC 81 ms
76,384 KB
testcase_24 AC 79 ms
76,420 KB
testcase_25 AC 81 ms
76,420 KB
testcase_26 AC 80 ms
76,036 KB
testcase_27 AC 80 ms
76,512 KB
testcase_28 AC 79 ms
76,552 KB
testcase_29 AC 81 ms
76,436 KB
testcase_30 AC 81 ms
76,556 KB
testcase_31 AC 82 ms
76,400 KB
testcase_32 AC 81 ms
76,408 KB
testcase_33 AC 82 ms
76,396 KB
testcase_34 AC 82 ms
76,428 KB
testcase_35 AC 82 ms
76,100 KB
testcase_36 AC 81 ms
76,136 KB
testcase_37 AC 82 ms
76,460 KB
testcase_38 AC 82 ms
76,424 KB
testcase_39 AC 82 ms
76,224 KB
testcase_40 AC 82 ms
76,536 KB
testcase_41 AC 81 ms
76,308 KB
testcase_42 AC 81 ms
76,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class INPUT:
  def __init__(self):
    self._l=open(0).read().split()
    self._length=len(self._l)
    self._index=0
    return

  def stream(self,k=1,f=int,f2=False):
    assert(-1<k)
    if self._length==self._index or self._length-self._index<k:
      raise Exception("There is no input!")
    elif f!=str:
      if k==0:
        ret=list(map(f,self._l[self._index:]))
        self._index=self._length
        return ret
      if k==1 and not f2:
        ret=f(self._l[self._index])
        self._index+=1
        return ret
      if k==1 and f2:
        ret=[f(self._l[self._index])]
        self._index+=1
        return ret
      ret=[]
      for _ in [0]*k:
        ret.append(f(self._l[self._index]))
        self._index+=1
      return ret
    else:
      if k==0:
        ret=list(self._l[self._index:])
        self._index=self._length
        return ret
      if k==1 and not f2:
        ret=self._l[self._index]
        self._index+=1
        return ret
      if k==1 and f2:
        ret=[self._l[self._index]]
        self._index+=1
        return ret
      ret=[]
      for _ in [0]*k:
        ret.append(self._l[self._index])
        self._index+=1
      return ret
pin=INPUT().stream

#pin(number[default:1],f[default:int],f2[default:False])
#if number==0 -> return left all
#listを変数で受け取るとき、必ずlistをTrueにすること。


def matrix_mul(A,B,mod):
  C=[[0]*len(B)for _ in[0]*len(A)]
  for i in range(len(A)):
    for k in range(len(B)):
      for j in range(len(B[0])):
        C[i][j]=(C[i][j]+A[i][k]*B[k][j])%mod
  return C

def matrix_exp(X,n,mod):
  Y=[[0]*len(X)for _ in[0]*len(X)]
  for i in range(len(X)):
    Y[i][i]=1
  while n>0:
    if n&1:
      Y=matrix_mul(Y,X,mod)
    X=matrix_mul(X,X,mod)
    n>>=1
  return Y

def calculate_nth(mod,n,A,C):
  A=matrix_exp(A,n,mod)
  res=matrix_mul(A,[[1],[0],[C],[0]],mod)
  return res[2][0]



def main():
  mod=10**9+7
  C,N,M=pin(3)
  A=[[1,0,0,1],[0,1,C-1,C-2],[C,0,0,0],[0,C,0,0]]
  ans=calculate_nth(mod,N,A,C)
  B=pow(pow(C,mod-2,mod),N+1,mod)
  # A にいる確率
  a=ans*B%mod
  # A にいない確率
  b=(1-a)%mod
  # M台がAに1台もいない確率
  c=pow(b,M,mod)
  # 余事象
  d=(1-c)%mod
  print(d)
  return

main()
0