結果

問題 No.1097 Remainder Operation
ユーザー prussian_coderprussian_coder
提出日時 2022-04-07 22:51:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 351 ms / 2,000 ms
コード長 486 bytes
コンパイル時間 280 ms
コンパイル使用メモリ 86,972 KB
実行使用メモリ 107,192 KB
最終ジャッジ日時 2023-08-18 18:57:18
合計ジャッジ時間 8,232 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,180 KB
testcase_01 AC 69 ms
71,112 KB
testcase_02 AC 73 ms
71,296 KB
testcase_03 AC 74 ms
71,364 KB
testcase_04 AC 71 ms
71,160 KB
testcase_05 AC 71 ms
71,372 KB
testcase_06 AC 71 ms
71,528 KB
testcase_07 AC 128 ms
78,568 KB
testcase_08 AC 126 ms
78,448 KB
testcase_09 AC 130 ms
78,636 KB
testcase_10 AC 128 ms
78,596 KB
testcase_11 AC 127 ms
78,568 KB
testcase_12 AC 323 ms
85,488 KB
testcase_13 AC 328 ms
85,688 KB
testcase_14 AC 329 ms
85,788 KB
testcase_15 AC 320 ms
85,820 KB
testcase_16 AC 332 ms
85,376 KB
testcase_17 AC 325 ms
85,700 KB
testcase_18 AC 329 ms
107,004 KB
testcase_19 AC 350 ms
107,192 KB
testcase_20 AC 348 ms
106,800 KB
testcase_21 AC 351 ms
106,960 KB
testcase_22 AC 348 ms
106,956 KB
権限があれば一括ダウンロードができます

ソースコード

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
	  if K>q:
	    b += ans[K-q+D[a%N][1]-1] - D[a%N][0]
	  print(b)  
for _ in range(int(input())):
	res(int(input()))  
0