結果

問題 No.1097 Remainder Operation
ユーザー prussian_coderprussian_coder
提出日時 2022-04-07 22:41:51
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 471 bytes
コンパイル時間 315 ms
コンパイル使用メモリ 87,084 KB
実行使用メモリ 111,928 KB
最終ジャッジ日時 2023-08-18 18:55:31
合計ジャッジ時間 12,529 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,388 KB
testcase_01 AC 63 ms
71,316 KB
testcase_02 AC 67 ms
71,332 KB
testcase_03 AC 66 ms
71,212 KB
testcase_04 AC 65 ms
71,400 KB
testcase_05 AC 67 ms
71,092 KB
testcase_06 AC 66 ms
71,196 KB
testcase_07 AC 146 ms
78,308 KB
testcase_08 AC 125 ms
77,432 KB
testcase_09 AC 126 ms
77,524 KB
testcase_10 AC 119 ms
77,428 KB
testcase_11 AC 117 ms
77,624 KB
testcase_12 AC 343 ms
85,440 KB
testcase_13 AC 425 ms
85,620 KB
testcase_14 AC 508 ms
85,556 KB
testcase_15 AC 666 ms
85,416 KB
testcase_16 AC 377 ms
85,564 KB
testcase_17 AC 292 ms
85,820 KB
testcase_18 AC 315 ms
106,896 KB
testcase_19 AC 331 ms
106,916 KB
testcase_20 AC 343 ms
106,892 KB
testcase_21 TLE -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
A=[int(x) for x in input().split()]
D=dict()
a=0
t=0
D[0]=(0,0)
p=0
ans = []
while True:
  p+=1
  a+=A[a%N]
  ans.append(a)
  if not a%N in D:
    D[a%N]=(a,p)
  else:
    break
    
cycle = p - D[a%N][1]
score = a - D[a%N][0]

    
def res(K):   
	if p>K-1:    
	  print(ans[K-1])
	else:
	  b = a + ((K-p)//cycle)*score
	  q = p + ((K-p)//cycle)*cycle
	  while q<K:
	    q+=1
	    b+=A[b%N]
	  print(b)  
for _ in range(int(input())):
	res(int(input()))  
0