結果

問題 No.1097 Remainder Operation
ユーザー titiatitia
提出日時 2020-06-26 22:53:16
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 628 bytes
コンパイル時間 112 ms
コンパイル使用メモリ 10,880 KB
実行使用メモリ 24,700 KB
最終ジャッジ日時 2023-09-18 06:51:35
合計ジャッジ時間 10,357 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,820 KB
testcase_01 AC 17 ms
7,844 KB
testcase_02 AC 16 ms
7,928 KB
testcase_03 AC 17 ms
7,792 KB
testcase_04 AC 17 ms
7,780 KB
testcase_05 AC 17 ms
7,776 KB
testcase_06 WA -
testcase_07 AC 78 ms
9,508 KB
testcase_08 AC 79 ms
9,408 KB
testcase_09 AC 79 ms
9,500 KB
testcase_10 AC 79 ms
9,456 KB
testcase_11 AC 80 ms
9,500 KB
testcase_12 AC 693 ms
19,624 KB
testcase_13 AC 662 ms
19,616 KB
testcase_14 AC 663 ms
19,740 KB
testcase_15 AC 679 ms
19,628 KB
testcase_16 AC 671 ms
19,668 KB
testcase_17 WA -
testcase_18 AC 768 ms
24,700 KB
testcase_19 AC 716 ms
19,268 KB
testcase_20 AC 710 ms
19,192 KB
testcase_21 AC 768 ms
21,016 KB
testcase_22 AC 747 ms
21,132 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)-1

while USED[NOW]==0:
    USED[NOW]=1
    LOOP+=1
    ANS.append(NOW)
    NOW=E[NOW]
    
SUM=[0]
for a in ANS:
    SUM.append(SUM[-1]+A[a])

LSUM=SUM[Begin+LOOP]-SUM[Begin]

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