結果

問題 No.1097 Remainder Operation
ユーザー marroncastlemarroncastle
提出日時 2020-06-26 22:01:39
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 554 bytes
コンパイル時間 604 ms
コンパイル使用メモリ 10,836 KB
実行使用メモリ 22,540 KB
最終ジャッジ日時 2023-09-18 04:36:53
合計ジャッジ時間 4,524 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,716 KB
testcase_01 AC 16 ms
7,800 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 WA -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 AC 300 ms
19,820 KB
testcase_18 AC 310 ms
22,400 KB
testcase_19 AC 322 ms
22,468 KB
testcase_20 AC 322 ms
22,472 KB
testcase_21 AC 343 ms
22,540 KB
testcase_22 AC 342 ms
22,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve():
  ans = 0
  N = int(input())
  A = list(map(int, input().split()))
  lis = [0]
  visited = [-1]*N
  r = 0
  cnt = 0
  while visited[r]==-1:
    visited[r] = cnt
    lis.append(lis[-1]+A[r])
    r = (r+A[r])%N
    cnt += 1
  cycle = cnt - visited[r]
  add_per_cycle = lis[-1]-lis[r]
  first = visited[r]
  Q = int(input())
  ans = []
  for i in range(Q):
    k = int(input())
    if k<=first:
      ans.append(lis[k])
    else:
      ans.append(lis[first+(k-first)%cycle]+(k-first)//cycle*add_per_cycle)
  return ans
print(*solve(), sep='\n')
0