結果
問題 | No.1013 〇マス進む |
ユーザー | toyuzuko |
提出日時 | 2023-01-20 18:38:35 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 339 ms / 2,000 ms |
コード長 | 2,140 bytes |
コンパイル時間 | 166 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 140,696 KB |
最終ジャッジ日時 | 2024-06-23 07:08:52 |
合計ジャッジ時間 | 15,551 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 70 ms
67,328 KB |
testcase_01 | AC | 64 ms
67,456 KB |
testcase_02 | AC | 65 ms
67,456 KB |
testcase_03 | AC | 77 ms
72,704 KB |
testcase_04 | AC | 70 ms
70,400 KB |
testcase_05 | AC | 81 ms
73,088 KB |
testcase_06 | AC | 81 ms
72,576 KB |
testcase_07 | AC | 85 ms
73,728 KB |
testcase_08 | AC | 77 ms
72,704 KB |
testcase_09 | AC | 82 ms
73,856 KB |
testcase_10 | AC | 86 ms
73,984 KB |
testcase_11 | AC | 81 ms
73,088 KB |
testcase_12 | AC | 82 ms
74,624 KB |
testcase_13 | AC | 102 ms
80,512 KB |
testcase_14 | AC | 176 ms
108,416 KB |
testcase_15 | AC | 234 ms
119,016 KB |
testcase_16 | AC | 216 ms
115,712 KB |
testcase_17 | AC | 166 ms
104,448 KB |
testcase_18 | AC | 182 ms
110,236 KB |
testcase_19 | AC | 150 ms
96,768 KB |
testcase_20 | AC | 269 ms
138,088 KB |
testcase_21 | AC | 164 ms
102,400 KB |
testcase_22 | AC | 192 ms
111,760 KB |
testcase_23 | AC | 124 ms
87,680 KB |
testcase_24 | AC | 273 ms
139,296 KB |
testcase_25 | AC | 271 ms
137,700 KB |
testcase_26 | AC | 128 ms
87,936 KB |
testcase_27 | AC | 156 ms
101,248 KB |
testcase_28 | AC | 132 ms
87,808 KB |
testcase_29 | AC | 262 ms
136,864 KB |
testcase_30 | AC | 159 ms
98,560 KB |
testcase_31 | AC | 224 ms
116,736 KB |
testcase_32 | AC | 181 ms
107,136 KB |
testcase_33 | AC | 190 ms
107,392 KB |
testcase_34 | AC | 252 ms
117,064 KB |
testcase_35 | AC | 253 ms
114,384 KB |
testcase_36 | AC | 108 ms
81,024 KB |
testcase_37 | AC | 108 ms
81,024 KB |
testcase_38 | AC | 266 ms
120,836 KB |
testcase_39 | AC | 156 ms
93,952 KB |
testcase_40 | AC | 271 ms
116,780 KB |
testcase_41 | AC | 131 ms
88,448 KB |
testcase_42 | AC | 188 ms
105,344 KB |
testcase_43 | AC | 163 ms
95,360 KB |
testcase_44 | AC | 201 ms
107,392 KB |
testcase_45 | AC | 182 ms
104,064 KB |
testcase_46 | AC | 142 ms
89,088 KB |
testcase_47 | AC | 184 ms
105,344 KB |
testcase_48 | AC | 203 ms
110,680 KB |
testcase_49 | AC | 269 ms
116,628 KB |
testcase_50 | AC | 224 ms
116,736 KB |
testcase_51 | AC | 215 ms
113,124 KB |
testcase_52 | AC | 119 ms
84,608 KB |
testcase_53 | AC | 135 ms
87,168 KB |
testcase_54 | AC | 226 ms
114,252 KB |
testcase_55 | AC | 146 ms
90,112 KB |
testcase_56 | AC | 294 ms
132,436 KB |
testcase_57 | AC | 243 ms
115,712 KB |
testcase_58 | AC | 339 ms
140,496 KB |
testcase_59 | AC | 324 ms
140,696 KB |
testcase_60 | AC | 314 ms
140,508 KB |
testcase_61 | AC | 271 ms
139,856 KB |
testcase_62 | AC | 245 ms
140,240 KB |
testcase_63 | AC | 66 ms
67,200 KB |
testcase_64 | AC | 66 ms
67,584 KB |
ソースコード
from typing import List, Generic, Optional, Callable, TypeVar S = TypeVar('S') class FunctionalGraph(Generic[S]): def __init__(self, n: int, edge_to: List[S], node_val: Optional[List[S]] = None, nxt_node_val: Optional[List[S]] = None, op: Optional[Callable[[int, int], int]] = lambda fr, to: to) -> None: if node_val is None: node_val = list(range(n)) if nxt_node_val is None: nxt_node_val = [node_val[edge_to[i]] for i in range(n)] self.n = n self.edge_to = edge_to self.node_val = node_val self.nxt_node_val = nxt_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.nxt_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.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)] node_val = list(range(N)) nxt_node_val = [i + P[i] for i in range(N)] op = lambda fr, to: to + fr // N * N F = FunctionalGraph(N, edge_to, node_val, nxt_node_val, op) for i in range(N): res = F.prod(i, K) print(res + 1)