結果

問題 No.1706 Many Bus Stops (hard)
ユーザー harurunharurun
提出日時 2021-09-10 13:32:30
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,104 bytes
コンパイル時間 311 ms
コンパイル使用メモリ 86,756 KB
実行使用メモリ 76,712 KB
最終ジャッジ日時 2023-09-30 09:26:48
合計ジャッジ時間 6,227 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
70,828 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
権限があれば一括ダウンロードができます

ソースコード

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,M,C):
  # ex:fibonacci
  A=matrix_exp(A,n,mod)
  res=matrix_mul(A,[[M],[0],[C*M],[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-2,C-2],[C,0,0,0],[0,C,0,0]]
  ans=calculate_nth(mod,N,A,M,C)
  B=pow(pow(C,mod-2,mod),N+1,mod)
  print(ans*B)
  return

main()
0