結果

問題 No.1097 Remainder Operation
ユーザー neterukunneterukun
提出日時 2020-06-26 22:32:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 195 ms / 2,000 ms
コード長 837 bytes
コンパイル時間 266 ms
コンパイル使用メモリ 87,076 KB
実行使用メモリ 109,072 KB
最終ジャッジ日時 2023-09-18 05:57:43
合計ジャッジ時間 5,559 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,440 KB
testcase_01 AC 69 ms
71,440 KB
testcase_02 AC 70 ms
71,612 KB
testcase_03 AC 69 ms
71,632 KB
testcase_04 AC 71 ms
71,144 KB
testcase_05 AC 71 ms
71,604 KB
testcase_06 AC 71 ms
71,336 KB
testcase_07 AC 107 ms
77,640 KB
testcase_08 AC 105 ms
77,888 KB
testcase_09 AC 106 ms
77,836 KB
testcase_10 AC 106 ms
77,800 KB
testcase_11 AC 106 ms
77,712 KB
testcase_12 AC 171 ms
91,636 KB
testcase_13 AC 168 ms
91,728 KB
testcase_14 AC 169 ms
91,408 KB
testcase_15 AC 169 ms
91,500 KB
testcase_16 AC 167 ms
91,700 KB
testcase_17 AC 168 ms
92,060 KB
testcase_18 AC 189 ms
108,372 KB
testcase_19 AC 192 ms
109,072 KB
testcase_20 AC 192 ms
108,988 KB
testcase_21 AC 195 ms
109,000 KB
testcase_22 AC 193 ms
108,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
a = list(map(int, input().split()))
q = int(input())
k = [int(input()) for i in range(q)]

ans = [0]
ind = [-1]
memo = {}
for i in range(3 * n):
    tmp = ans[-1]
    r = tmp % n
    if r in memo:
        lap_length = len(ans) - memo[r]
        lap_diff = ans[-1] - ans[memo[r] - 1]
        init_length = len(ans) - lap_length - 1
        break
    memo[r] = len(ans)
    ans.append(tmp + a[r])
    ind.append(r)

ru = [0] * (lap_length + 1)
for i in range(lap_length):
    ru[i + 1] = ru[i] + ans[memo[r] + i] - ans[memo[r] - 1 + i]
  
#print(ans)
#print(ind)
#print(init_length, lap_length, lap_diff)
#print(ru)
for num in k:
    if num < len(ans):
        print(ans[num])
    else:
        res = ans[init_length]
        laps, rem = divmod(num - init_length, lap_length)
        print(res + laps * lap_diff + ru[rem])
0