結果

問題 No.1097 Remainder Operation
ユーザー takakintakakin
提出日時 2020-06-27 17:09:02
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 410 ms / 2,000 ms
コード長 572 bytes
コンパイル時間 177 ms
コンパイル使用メモリ 10,968 KB
実行使用メモリ 27,240 KB
最終ジャッジ日時 2023-09-19 05:34:11
合計ジャッジ時間 7,409 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
8,488 KB
testcase_01 AC 19 ms
8,584 KB
testcase_02 AC 19 ms
8,516 KB
testcase_03 AC 19 ms
8,472 KB
testcase_04 AC 19 ms
8,596 KB
testcase_05 AC 19 ms
8,596 KB
testcase_06 AC 20 ms
8,660 KB
testcase_07 AC 45 ms
9,496 KB
testcase_08 AC 46 ms
9,652 KB
testcase_09 AC 45 ms
9,532 KB
testcase_10 AC 46 ms
9,608 KB
testcase_11 AC 45 ms
9,696 KB
testcase_12 AC 300 ms
19,644 KB
testcase_13 AC 298 ms
19,776 KB
testcase_14 AC 307 ms
19,740 KB
testcase_15 AC 310 ms
19,776 KB
testcase_16 AC 296 ms
19,676 KB
testcase_17 AC 305 ms
19,712 KB
testcase_18 AC 383 ms
27,032 KB
testcase_19 AC 387 ms
27,240 KB
testcase_20 AC 394 ms
27,188 KB
testcase_21 AC 409 ms
27,196 KB
testcase_22 AC 410 ms
27,020 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
A=[int(i) for i in input().split()]
x=0
C=[False]*n
C[0]=True
import collections
D=collections.defaultdict(int)
Ans=[]
ct=1
while True:
  Ans.append(x)
  if D[x%n]!=0:
    st=D[x%n]
    ed=ct
    Ans.append(x+A[x%n])
    break
  else:
    D[x%n]=ct
    ct+=1
    x+=A[x%n]
q=int(input())
for _ in range(q):
  k=int(input())
  if k<=ed:
    print(Ans[k])
  else:
    ans=Ans[st]
    loop=(k-st)//(ed-st)
    ans+=loop*(Ans[ed]-Ans[st])
    rem=(k-st)%(ed-st)
    ans+=Ans[st+rem]-Ans[st]
    print(ans)
0