結果

問題 No.1595 The Final Digit
ユーザー harurunharurun
提出日時 2021-07-09 21:59:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 1,894 bytes
コンパイル時間 304 ms
コンパイル使用メモリ 87,084 KB
実行使用メモリ 76,204 KB
最終ジャッジ日時 2023-09-14 09:00:19
合計ジャッジ時間 3,219 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
71,624 KB
testcase_01 AC 79 ms
71,576 KB
testcase_02 AC 81 ms
71,756 KB
testcase_03 AC 80 ms
71,564 KB
testcase_04 AC 83 ms
71,780 KB
testcase_05 AC 85 ms
71,656 KB
testcase_06 AC 82 ms
71,740 KB
testcase_07 AC 85 ms
71,748 KB
testcase_08 AC 89 ms
71,764 KB
testcase_09 AC 82 ms
71,360 KB
testcase_10 AC 84 ms
71,588 KB
testcase_11 AC 81 ms
71,808 KB
testcase_12 AC 86 ms
76,164 KB
testcase_13 AC 84 ms
71,804 KB
testcase_14 AC 90 ms
76,204 KB
testcase_15 AC 90 ms
76,008 KB
testcase_16 AC 89 ms
71,720 KB
testcase_17 AC 90 ms
71,692 KB
testcase_18 AC 85 ms
71,560 KB
testcase_19 AC 84 ms
71,888 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にすること。

from collections import Counter
def main():
  p,q,r,K=pin(4)
  p%=10
  q%=10
  r%=10
  A=[p,q,r]
  S=Counter()
  for i in range(K-3):
    t=(A[i]+A[i+1]+A[i+2])%10
    #print(S[(A[i],A[i+1],A[i+2])])
    if S[(A[i],A[i+1],A[i+2])]!=0:
      u=S[(A[i],A[i+1],A[i+2])]-1
      loop=i-u
      left=K-i-1
      v=left%loop
      print(A[u+v])
      #print(A)
      #print(u,v)
      #print(i,len(A))
      #print(left,loop)
      return
    S[(A[i],A[i+1],A[i+2])]=i+1
    A.append(t)
  print(A[-1])
  #print(A)
  return

main()
0