結果

問題 No.1097 Remainder Operation
ユーザー titiatitia
提出日時 2020-06-26 22:59:51
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 802 ms / 2,000 ms
コード長 721 bytes
コンパイル時間 750 ms
コンパイル使用メモリ 10,948 KB
実行使用メモリ 24,752 KB
最終ジャッジ日時 2023-09-18 07:05:40
合計ジャッジ時間 10,559 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,052 KB
testcase_01 AC 16 ms
7,860 KB
testcase_02 AC 17 ms
7,928 KB
testcase_03 AC 16 ms
7,904 KB
testcase_04 AC 17 ms
7,936 KB
testcase_05 AC 17 ms
7,920 KB
testcase_06 AC 17 ms
7,916 KB
testcase_07 AC 80 ms
9,416 KB
testcase_08 AC 82 ms
9,264 KB
testcase_09 AC 82 ms
9,560 KB
testcase_10 AC 81 ms
9,588 KB
testcase_11 AC 83 ms
9,412 KB
testcase_12 AC 686 ms
19,716 KB
testcase_13 AC 691 ms
19,672 KB
testcase_14 AC 707 ms
19,736 KB
testcase_15 AC 693 ms
19,752 KB
testcase_16 AC 695 ms
19,596 KB
testcase_17 AC 693 ms
19,724 KB
testcase_18 AC 802 ms
24,752 KB
testcase_19 AC 733 ms
19,252 KB
testcase_20 AC 744 ms
19,148 KB
testcase_21 AC 778 ms
21,100 KB
testcase_22 AC 777 ms
21,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)

    
    
0