結果
問題 | No.1013 〇マス進む |
ユーザー | tamato |
提出日時 | 2020-03-20 23:17:06 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,997 bytes |
コンパイル時間 | 357 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 97,280 KB |
最終ジャッジ日時 | 2024-12-15 14:57:43 |
合計ジャッジ時間 | 11,985 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
53,632 KB |
testcase_01 | AC | 43 ms
53,888 KB |
testcase_02 | AC | 43 ms
54,016 KB |
testcase_03 | AC | 47 ms
54,656 KB |
testcase_04 | AC | 46 ms
54,784 KB |
testcase_05 | AC | 46 ms
55,040 KB |
testcase_06 | WA | - |
testcase_07 | AC | 49 ms
55,296 KB |
testcase_08 | AC | 48 ms
55,424 KB |
testcase_09 | AC | 52 ms
61,184 KB |
testcase_10 | WA | - |
testcase_11 | AC | 46 ms
54,656 KB |
testcase_12 | WA | - |
testcase_13 | AC | 93 ms
77,460 KB |
testcase_14 | AC | 138 ms
88,064 KB |
testcase_15 | AC | 184 ms
94,848 KB |
testcase_16 | AC | 177 ms
92,928 KB |
testcase_17 | AC | 126 ms
85,888 KB |
testcase_18 | AC | 150 ms
88,184 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | AC | 123 ms
84,864 KB |
testcase_22 | AC | 157 ms
89,168 KB |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | AC | 98 ms
79,232 KB |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | AC | 120 ms
83,456 KB |
testcase_31 | AC | 158 ms
90,732 KB |
testcase_32 | AC | 142 ms
87,552 KB |
testcase_33 | AC | 143 ms
87,900 KB |
testcase_34 | AC | 183 ms
94,208 KB |
testcase_35 | AC | 174 ms
92,416 KB |
testcase_36 | AC | 91 ms
77,652 KB |
testcase_37 | AC | 94 ms
77,824 KB |
testcase_38 | AC | 181 ms
94,160 KB |
testcase_39 | AC | 111 ms
81,792 KB |
testcase_40 | AC | 179 ms
94,336 KB |
testcase_41 | AC | 99 ms
78,976 KB |
testcase_42 | AC | 141 ms
85,888 KB |
testcase_43 | AC | 118 ms
82,172 KB |
testcase_44 | AC | 137 ms
87,552 KB |
testcase_45 | AC | 140 ms
86,144 KB |
testcase_46 | AC | 102 ms
79,616 KB |
testcase_47 | AC | 140 ms
86,272 KB |
testcase_48 | AC | 154 ms
88,800 KB |
testcase_49 | AC | 171 ms
92,824 KB |
testcase_50 | AC | 170 ms
90,624 KB |
testcase_51 | AC | 155 ms
89,268 KB |
testcase_52 | AC | 93 ms
78,336 KB |
testcase_53 | AC | 110 ms
78,848 KB |
testcase_54 | AC | 177 ms
92,672 KB |
testcase_55 | AC | 105 ms
80,000 KB |
testcase_56 | AC | 194 ms
95,604 KB |
testcase_57 | AC | 157 ms
90,240 KB |
testcase_58 | AC | 200 ms
97,144 KB |
testcase_59 | AC | 206 ms
97,152 KB |
testcase_60 | AC | 198 ms
97,024 KB |
testcase_61 | WA | - |
testcase_62 | WA | - |
testcase_63 | AC | 43 ms
54,016 KB |
testcase_64 | AC | 44 ms
54,016 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()