結果

問題 No.1013 〇マス進む
ユーザー toyuzukotoyuzuko
提出日時 2023-01-20 18:49:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 369 ms / 2,000 ms
コード長 2,177 bytes
コンパイル時間 345 ms
コンパイル使用メモリ 82,168 KB
実行使用メモリ 140,512 KB
最終ジャッジ日時 2024-06-23 07:15:21
合計ジャッジ時間 15,165 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
67,328 KB
testcase_01 AC 65 ms
67,200 KB
testcase_02 AC 66 ms
67,072 KB
testcase_03 AC 77 ms
72,448 KB
testcase_04 AC 76 ms
70,656 KB
testcase_05 AC 78 ms
73,472 KB
testcase_06 AC 76 ms
72,704 KB
testcase_07 AC 80 ms
73,472 KB
testcase_08 AC 81 ms
72,576 KB
testcase_09 AC 84 ms
73,856 KB
testcase_10 AC 81 ms
73,856 KB
testcase_11 AC 77 ms
72,704 KB
testcase_12 AC 80 ms
74,752 KB
testcase_13 AC 108 ms
80,692 KB
testcase_14 AC 180 ms
108,288 KB
testcase_15 AC 250 ms
119,120 KB
testcase_16 AC 230 ms
115,548 KB
testcase_17 AC 171 ms
104,364 KB
testcase_18 AC 193 ms
110,384 KB
testcase_19 AC 149 ms
96,768 KB
testcase_20 AC 273 ms
137,736 KB
testcase_21 AC 161 ms
101,888 KB
testcase_22 AC 198 ms
111,472 KB
testcase_23 AC 125 ms
87,424 KB
testcase_24 AC 288 ms
139,428 KB
testcase_25 AC 285 ms
137,924 KB
testcase_26 AC 127 ms
87,552 KB
testcase_27 AC 156 ms
100,980 KB
testcase_28 AC 128 ms
87,808 KB
testcase_29 AC 277 ms
136,564 KB
testcase_30 AC 160 ms
98,304 KB
testcase_31 AC 207 ms
116,992 KB
testcase_32 AC 173 ms
107,136 KB
testcase_33 AC 187 ms
107,008 KB
testcase_34 AC 261 ms
116,644 KB
testcase_35 AC 257 ms
114,368 KB
testcase_36 AC 109 ms
81,024 KB
testcase_37 AC 109 ms
81,024 KB
testcase_38 AC 259 ms
120,436 KB
testcase_39 AC 150 ms
94,148 KB
testcase_40 AC 288 ms
116,752 KB
testcase_41 AC 135 ms
88,436 KB
testcase_42 AC 196 ms
105,536 KB
testcase_43 AC 161 ms
95,360 KB
testcase_44 AC 197 ms
107,316 KB
testcase_45 AC 184 ms
104,296 KB
testcase_46 AC 140 ms
89,116 KB
testcase_47 AC 190 ms
105,344 KB
testcase_48 AC 205 ms
110,560 KB
testcase_49 AC 285 ms
116,740 KB
testcase_50 AC 236 ms
116,980 KB
testcase_51 AC 227 ms
112,928 KB
testcase_52 AC 122 ms
84,224 KB
testcase_53 AC 132 ms
87,136 KB
testcase_54 AC 223 ms
114,260 KB
testcase_55 AC 145 ms
89,704 KB
testcase_56 AC 300 ms
124,520 KB
testcase_57 AC 254 ms
115,456 KB
testcase_58 AC 369 ms
140,380 KB
testcase_59 AC 343 ms
140,480 KB
testcase_60 AC 315 ms
140,512 KB
testcase_61 AC 274 ms
140,112 KB
testcase_62 AC 251 ms
139,964 KB
testcase_63 AC 65 ms
67,072 KB
testcase_64 AC 64 ms
67,072 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