結果

問題 No.1013 〇マス進む
ユーザー toyuzukotoyuzuko
提出日時 2023-01-20 18:49:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 468 ms / 2,000 ms
コード長 2,177 bytes
コンパイル時間 673 ms
コンパイル使用メモリ 87,332 KB
実行使用メモリ 149,936 KB
最終ジャッジ日時 2023-09-05 11:37:35
合計ジャッジ時間 23,159 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 171 ms
80,320 KB
testcase_01 AC 172 ms
80,252 KB
testcase_02 AC 175 ms
80,264 KB
testcase_03 AC 193 ms
81,884 KB
testcase_04 AC 185 ms
81,604 KB
testcase_05 AC 187 ms
82,032 KB
testcase_06 AC 187 ms
82,064 KB
testcase_07 AC 191 ms
82,008 KB
testcase_08 AC 187 ms
82,020 KB
testcase_09 AC 191 ms
82,436 KB
testcase_10 AC 192 ms
82,172 KB
testcase_11 AC 190 ms
81,820 KB
testcase_12 AC 197 ms
82,452 KB
testcase_13 AC 215 ms
83,024 KB
testcase_14 AC 294 ms
113,348 KB
testcase_15 AC 366 ms
134,604 KB
testcase_16 AC 346 ms
129,756 KB
testcase_17 AC 275 ms
109,124 KB
testcase_18 AC 308 ms
116,396 KB
testcase_19 AC 269 ms
100,460 KB
testcase_20 AC 397 ms
147,280 KB
testcase_21 AC 267 ms
106,384 KB
testcase_22 AC 304 ms
117,908 KB
testcase_23 AC 231 ms
92,336 KB
testcase_24 AC 393 ms
148,812 KB
testcase_25 AC 382 ms
147,656 KB
testcase_26 AC 231 ms
92,116 KB
testcase_27 AC 262 ms
104,948 KB
testcase_28 AC 234 ms
92,560 KB
testcase_29 AC 369 ms
145,772 KB
testcase_30 AC 264 ms
102,224 KB
testcase_31 AC 319 ms
123,516 KB
testcase_32 AC 276 ms
112,148 KB
testcase_33 AC 289 ms
112,052 KB
testcase_34 AC 370 ms
132,008 KB
testcase_35 AC 381 ms
128,608 KB
testcase_36 AC 219 ms
83,388 KB
testcase_37 AC 212 ms
82,988 KB
testcase_38 AC 382 ms
136,352 KB
testcase_39 AC 264 ms
97,960 KB
testcase_40 AC 415 ms
131,860 KB
testcase_41 AC 241 ms
93,004 KB
testcase_42 AC 299 ms
110,248 KB
testcase_43 AC 265 ms
98,904 KB
testcase_44 AC 304 ms
112,612 KB
testcase_45 AC 290 ms
108,464 KB
testcase_46 AC 254 ms
93,804 KB
testcase_47 AC 297 ms
110,328 KB
testcase_48 AC 311 ms
116,712 KB
testcase_49 AC 392 ms
130,488 KB
testcase_50 AC 341 ms
123,684 KB
testcase_51 AC 329 ms
118,800 KB
testcase_52 AC 228 ms
88,272 KB
testcase_53 AC 238 ms
91,568 KB
testcase_54 AC 331 ms
128,092 KB
testcase_55 AC 249 ms
94,516 KB
testcase_56 AC 412 ms
141,044 KB
testcase_57 AC 362 ms
121,952 KB
testcase_58 AC 468 ms
149,936 KB
testcase_59 AC 443 ms
149,752 KB
testcase_60 AC 414 ms
149,740 KB
testcase_61 AC 371 ms
149,216 KB
testcase_62 AC 350 ms
149,744 KB
testcase_63 AC 173 ms
80,344 KB
testcase_64 AC 174 ms
80,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from typing import List, Generic, Optional, Callable, TypeVar

S = TypeVar('S')

class FunctionalGraph(Generic[S]):
    def __init__(self, n: int, edge_to: List[S], init_node_val: Optional[List[S]] = None, next_node_val: Optional[List[S]] = None, op: Callable[[int, int], int]= lambda fr, to: to) -> None:
        if init_node_val is None: init_node_val = list(range(n))
        if next_node_val is None: next_node_val = [node_val[edge_to[i]] for i in range(n)]
        self.n = n
        self.edge_to = edge_to
        self.init_node_val = init_node_val
        self.next_node_val = next_node_val
        self.op = op
        self.built = False
       
    def build_doubling(self, bit_max: int = 31):
        self.built = True
        self.bit_max = bit_max
        self.dub = [[-1] * self.n for _ in range(self.bit_max)]
        self.dp = [[-1] * self.n for _ in range(self.bit_max)]
        for i in range(self.n):
            self.dub[0][i] = self.edge_to[i]
            self.dp[0][i] = self.next_node_val[i]
        for i in range(1, self.bit_max):
            for j in range(self.n):
                if self.dub[i - 1][j] != -1:
                    self.dub[i][j] = self.dub[i - 1][self.dub[i - 1][j]]
                    self.dp[i][j] = self.op(self.dp[i - 1][j], self.dp[i - 1][self.dub[i - 1][j]])

    def get(self, v: int, k: int) -> int:
        if not self.built: self.build_doubling()
        for i in range(1, self.bit_max):
            if k & (1 << i):
                v = self.dub[i][v]
        return v

    def prod(self, v: int, k: int) -> S:
        if not self.built: self.build_doubling()
        res = self.init_node_val[v]
        for i in range(self.bit_max):
            if k & (1 << i):
                res = self.op(res, self.dp[i][v])
                v = self.dub[i][v]
        return res

N, K = map(int, input().split())
P = list(map(int, input().split()))

edge_to = [(i + P[i]) % N for i in range(N)]
init_node_val = list(range(N))
next_node_val = [i + P[i] for i in range(N)]
op = lambda fr, to: to + fr // N * N

F = FunctionalGraph(N, edge_to, init_node_val, next_node_val, op)

for i in range(N):
    res = F.prod(i, K)
    print(res + 1)
0