結果

問題 No.1013 〇マス進む
ユーザー toyuzukotoyuzuko
提出日時 2023-01-20 18:04:14
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,008 bytes
コンパイル時間 1,130 ms
コンパイル使用メモリ 86,776 KB
実行使用メモリ 107,156 KB
最終ジャッジ日時 2023-09-05 11:08:07
合計ジャッジ時間 22,027 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 172 ms
80,188 KB
testcase_01 AC 172 ms
80,220 KB
testcase_02 AC 174 ms
80,156 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 185 ms
81,948 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 AC 258 ms
106,652 KB
testcase_63 AC 173 ms
80,296 KB
testcase_64 WA -
権限があれば一括ダウンロードができます

ソースコード

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], node_val: Optional[List[S]] = None, op: Callable[[int, int], int] = lambda fr, to: to) -> None:
        if node_val is None: node_val = list(range(n))
        self.n = n
        self.edge_to = edge_to
        self.node_val = 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.node_val[i] # node_valを1回移動後の値にする?
        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(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 = 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 = [0] * N

for i in range(N):
    node_val[i] = i + P[i]

def op(fr, to):
    return to + fr // N * N

F = FunctionalGraph(N, edge_to, node_val, op)
F.build_doubling(4)

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