結果

問題 No.1097 Remainder Operation
ユーザー marroncastlemarroncastle
提出日時 2020-06-26 22:14:11
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 347 ms / 2,000 ms
コード長 561 bytes
コンパイル時間 366 ms
コンパイル使用メモリ 10,740 KB
実行使用メモリ 22,504 KB
最終ジャッジ日時 2023-09-18 05:16:09
合計ジャッジ時間 6,149 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,788 KB
testcase_01 AC 15 ms
7,820 KB
testcase_02 AC 16 ms
7,780 KB
testcase_03 AC 15 ms
7,940 KB
testcase_04 AC 16 ms
7,748 KB
testcase_05 AC 16 ms
7,792 KB
testcase_06 AC 16 ms
7,796 KB
testcase_07 AC 42 ms
9,516 KB
testcase_08 AC 43 ms
9,396 KB
testcase_09 AC 42 ms
9,320 KB
testcase_10 AC 42 ms
9,324 KB
testcase_11 AC 42 ms
9,324 KB
testcase_12 AC 297 ms
19,704 KB
testcase_13 AC 298 ms
19,576 KB
testcase_14 AC 301 ms
19,660 KB
testcase_15 AC 300 ms
19,592 KB
testcase_16 AC 298 ms
19,596 KB
testcase_17 AC 299 ms
19,796 KB
testcase_18 AC 314 ms
22,352 KB
testcase_19 AC 321 ms
22,504 KB
testcase_20 AC 323 ms
22,344 KB
testcase_21 AC 342 ms
22,476 KB
testcase_22 AC 347 ms
22,468 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[-cycle-1]
  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