結果
| 問題 | 
                            No.1097 Remainder Operation
                             | 
                    
| コンテスト | |
| ユーザー | 
                             tktk_snsn
                         | 
                    
| 提出日時 | 2020-12-15 23:29:37 | 
| 言語 | Python3  (3.13.1 + numpy 2.2.1 + scipy 1.14.1)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 328 ms / 2,000 ms | 
| コード長 | 772 bytes | 
| コンパイル時間 | 91 ms | 
| コンパイル使用メモリ | 12,928 KB | 
| 実行使用メモリ | 21,728 KB | 
| 最終ジャッジ日時 | 2024-09-20 02:27:44 | 
| 合計ジャッジ時間 | 6,316 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 21 | 
ソースコード
from itertools import accumulate
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
N = int(input())
A = list(map(int, input().split()))
seen = [0] * N
first = [0]
second = [0]
x = 0
while True:
    i = x % N
    if seen[i] == 0:
        first.append(A[i])
        x += A[i]
        seen[i] = 1
    elif seen[i] == 1:
        second.append(A[i])
        x += A[i]
        seen[i] = 2
    elif seen[i] >= 2:
        break
F = list(accumulate(first))
S = list(accumulate(second))
LF = len(F) - 1
LS = len(S) - 1
def cnt(k):
    if k <= LF:
        return F[k]
    res = F[LF]
    k -= LF
    d, m = divmod(k, LS)
    res += d * S[LS]
    res += S[m]
    return res
Q = int(input())
for _ in range(Q):
    k = int(input())
    print(cnt(k))
            
            
            
        
            
tktk_snsn