結果

問題 No.1097 Remainder Operation
ユーザー 👑 KazunKazun
提出日時 2020-06-26 22:35:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 362 ms / 2,000 ms
コード長 495 bytes
コンパイル時間 394 ms
コンパイル使用メモリ 86,936 KB
実行使用メモリ 116,212 KB
最終ジャッジ日時 2023-09-18 06:01:34
合計ジャッジ時間 7,598 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
71,348 KB
testcase_01 AC 67 ms
71,416 KB
testcase_02 AC 69 ms
71,424 KB
testcase_03 AC 73 ms
71,324 KB
testcase_04 AC 72 ms
71,076 KB
testcase_05 AC 73 ms
71,396 KB
testcase_06 AC 76 ms
71,260 KB
testcase_07 AC 134 ms
78,588 KB
testcase_08 AC 133 ms
78,244 KB
testcase_09 AC 135 ms
78,408 KB
testcase_10 AC 136 ms
78,336 KB
testcase_11 AC 134 ms
78,448 KB
testcase_12 AC 340 ms
90,836 KB
testcase_13 AC 347 ms
91,028 KB
testcase_14 AC 332 ms
90,984 KB
testcase_15 AC 338 ms
90,992 KB
testcase_16 AC 344 ms
90,868 KB
testcase_17 AC 339 ms
91,156 KB
testcase_18 AC 360 ms
116,208 KB
testcase_19 AC 362 ms
116,024 KB
testcase_20 AC 352 ms
116,212 KB
testcase_21 AC 357 ms
115,240 KB
testcase_22 AC 356 ms
115,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
A=list(map(int,input().split()))
Q=int(input())

P=set()
H=[]

s=0
while s not in P:
    P.add(s)
    H.append(s)
    
    s=(s+A[s])%N

L=H.index(s)+1

T=[0]
for i in range(L):
    T.append(T[-1]+A[T[-1]%N])

Y=T[-1]
U=[0]
for i in range(len(H)-L+1):
    U.append(U[-1]+A[(Y+U[-1])%N])

for _ in range(Q):
    x=int(input())
    if x<=L:
        print(T[x])
    else:
        R=(x-L)
        E=R//(len(H)-L+1)
        F=R%(len(H)-L+1)
        
        print(T[-1]+U[-1]*E+U[F])

0