結果
| 問題 |
No.1097 Remainder Operation
|
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2020-06-26 22:59:51 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 825 ms / 2,000 ms |
| コード長 | 721 bytes |
| コンパイル時間 | 83 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 27,264 KB |
| 最終ジャッジ日時 | 2024-07-04 23:16:49 |
| 合計ジャッジ時間 | 11,145 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 21 |
ソースコード
N=int(input())
A=list(map(int,input().split()))
E=[(A[i]+i)%N for i in range(N)]
NOW=0
USED=[0]*N
ANS=[]
while USED[NOW]==0:
USED[NOW]=1
ANS.append(NOW)
NOW=E[NOW]
USED=[0]*N
NOW=ANS[-1]
ANS.pop()
LOOP=0
Begin=len(ANS)
#print(Begin,ANS,NOW)
while USED[NOW]==0:
USED[NOW]=1
LOOP+=1
ANS.append(NOW)
NOW=E[NOW]
for i in range(10):
USED[NOW]=1
ANS.append(NOW)
NOW=E[NOW]
SUM=[0]
for a in ANS:
SUM.append(SUM[-1]+A[a])
LSUM=SUM[Begin+5+LOOP]-SUM[Begin+5]
Q=int(input())
for tests in range(Q):
K=int(input())
if K<len(ANS):
print(SUM[K])
else:
rest=K-(len(ANS)-1)
LL=(rest+LOOP-1)//LOOP
print(SUM[K-LL*LOOP]+LL*LSUM)
titia