結果
問題 | No.1013 〇マス進む |
ユーザー | tamato |
提出日時 | 2020-03-20 23:17:06 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,997 bytes |
コンパイル時間 | 379 ms |
コンパイル使用メモリ | 82,260 KB |
実行使用メモリ | 97,632 KB |
最終ジャッジ日時 | 2024-05-09 05:15:25 |
合計ジャッジ時間 | 11,524 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
55,124 KB |
testcase_01 | AC | 39 ms
53,732 KB |
testcase_02 | AC | 40 ms
54,236 KB |
testcase_03 | AC | 41 ms
54,728 KB |
testcase_04 | AC | 43 ms
55,868 KB |
testcase_05 | AC | 40 ms
55,188 KB |
testcase_06 | WA | - |
testcase_07 | AC | 45 ms
56,524 KB |
testcase_08 | AC | 43 ms
56,016 KB |
testcase_09 | AC | 47 ms
62,556 KB |
testcase_10 | WA | - |
testcase_11 | AC | 41 ms
55,316 KB |
testcase_12 | WA | - |
testcase_13 | AC | 85 ms
77,724 KB |
testcase_14 | AC | 133 ms
87,800 KB |
testcase_15 | AC | 154 ms
95,112 KB |
testcase_16 | AC | 149 ms
92,940 KB |
testcase_17 | AC | 108 ms
85,888 KB |
testcase_18 | AC | 124 ms
89,028 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | AC | 107 ms
84,960 KB |
testcase_22 | AC | 130 ms
89,256 KB |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | AC | 88 ms
79,172 KB |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | AC | 103 ms
83,368 KB |
testcase_31 | AC | 135 ms
90,576 KB |
testcase_32 | AC | 125 ms
87,844 KB |
testcase_33 | AC | 124 ms
87,984 KB |
testcase_34 | AC | 156 ms
94,260 KB |
testcase_35 | AC | 158 ms
92,652 KB |
testcase_36 | AC | 84 ms
77,720 KB |
testcase_37 | AC | 81 ms
77,800 KB |
testcase_38 | AC | 157 ms
94,000 KB |
testcase_39 | AC | 102 ms
81,648 KB |
testcase_40 | AC | 163 ms
94,164 KB |
testcase_41 | AC | 91 ms
79,380 KB |
testcase_42 | AC | 121 ms
86,196 KB |
testcase_43 | AC | 103 ms
82,112 KB |
testcase_44 | AC | 183 ms
87,820 KB |
testcase_45 | AC | 122 ms
86,132 KB |
testcase_46 | AC | 93 ms
79,660 KB |
testcase_47 | AC | 121 ms
86,388 KB |
testcase_48 | AC | 132 ms
88,728 KB |
testcase_49 | AC | 146 ms
92,932 KB |
testcase_50 | AC | 149 ms
90,776 KB |
testcase_51 | AC | 134 ms
89,360 KB |
testcase_52 | AC | 84 ms
78,372 KB |
testcase_53 | AC | 104 ms
78,916 KB |
testcase_54 | AC | 159 ms
92,668 KB |
testcase_55 | AC | 94 ms
80,128 KB |
testcase_56 | AC | 172 ms
95,604 KB |
testcase_57 | AC | 139 ms
90,380 KB |
testcase_58 | AC | 175 ms
97,068 KB |
testcase_59 | AC | 186 ms
96,884 KB |
testcase_60 | AC | 170 ms
97,268 KB |
testcase_61 | WA | - |
testcase_62 | WA | - |
testcase_63 | AC | 40 ms
54,092 KB |
testcase_64 | AC | 40 ms
54,068 KB |
ソースコード
def main(): import sys from collections import deque input = sys.stdin.readline N, K = map(int, input().split()) P = list(map(int, input().split())) ans = [-1] * (N+1) dest = [0] * (N+1) to = [0] * (N+1) rev = [[] for _ in range(N+1)] for i in range(1, N+1): to[i] = i + P[i-1] if to[i] > N: to[i] -= N rev[to[i]].append(i) seen = [0] * (N+1) for i in range(1, N+1): if seen[i] == 0: x = i cycle = [] while True: if seen[x] == 2: break if seen[x]: cycle.append(x) seen[x] += 1 x = to[x] #print(i, seen, cycle, ans) L = len(cycle) cs = [0] * (L+1) cs[0] = cycle[0] for j in range(L): cs[j+1] = cs[j] + P[cycle[j]-1] d, m = divmod(K, L) ans[cycle[0]] = d * (cs[-1] - cs[0]) + cs[m] last = cycle[m%L] dest[cycle[0]] = last for j in range(1, L): v = cycle[j] u = cycle[j-1] ans[v] = ans[u] + P[last-1] last = to[last] dest[v] = last if cycle[j] <= cycle[j-1]: ans[v] -= N c2i = {cycle[j]: j for j in range(L)} que = deque() for v in cycle: for u in rev[v]: if u not in c2i: que.append(u) while que: v = que.popleft() seen[v] = 3 u = to[v] w = cycle[c2i[dest[u]] - 1] dest[v] = w ans[v] = ans[u] - P[w-1] if v >= u: ans[v] += N for uu in rev[v]: que.append(uu) for a in ans[1:]: print(a) if __name__ == '__main__': main()