結果
| 問題 | 
                            No.1097 Remainder Operation
                             | 
                    
| コンテスト | |
| ユーザー | 
                             prussian_coder
                         | 
                    
| 提出日時 | 2022-04-07 22:51:57 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 314 ms / 2,000 ms | 
| コード長 | 486 bytes | 
| コンパイル時間 | 357 ms | 
| コンパイル使用メモリ | 81,664 KB | 
| 実行使用メモリ | 105,856 KB | 
| 最終ジャッジ日時 | 2024-11-28 02:14:38 | 
| 合計ジャッジ時間 | 6,432 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 21 | 
ソースコード
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()))  
            
            
            
        
            
prussian_coder