結果

問題 No.1765 While Shining
ユーザー ThetaTheta
提出日時 2022-10-24 19:38:08
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 242 ms / 2,000 ms
コード長 782 bytes
コンパイル時間 80 ms
コンパイル使用メモリ 10,908 KB
実行使用メモリ 12,504 KB
最終ジャッジ日時 2023-09-15 21:16:18
合計ジャッジ時間 5,201 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
8,552 KB
testcase_01 AC 20 ms
8,560 KB
testcase_02 AC 21 ms
8,564 KB
testcase_03 AC 20 ms
8,676 KB
testcase_04 AC 21 ms
8,640 KB
testcase_05 AC 22 ms
8,660 KB
testcase_06 AC 21 ms
8,584 KB
testcase_07 AC 21 ms
8,728 KB
testcase_08 AC 22 ms
8,592 KB
testcase_09 AC 151 ms
10,876 KB
testcase_10 AC 207 ms
11,820 KB
testcase_11 AC 187 ms
11,360 KB
testcase_12 AC 202 ms
11,484 KB
testcase_13 AC 180 ms
11,644 KB
testcase_14 AC 222 ms
12,368 KB
testcase_15 AC 223 ms
12,388 KB
testcase_16 AC 221 ms
12,324 KB
testcase_17 AC 219 ms
12,304 KB
testcase_18 AC 220 ms
12,496 KB
testcase_19 AC 224 ms
12,504 KB
testcase_20 AC 219 ms
12,372 KB
testcase_21 AC 218 ms
12,312 KB
testcase_22 AC 220 ms
12,332 KB
testcase_23 AC 222 ms
12,312 KB
testcase_24 AC 242 ms
12,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from functools import lru_cache


class Board:
    def __init__(self, board: list[int]) -> None:
        self.board = board

    @lru_cache
    def calc_move_times(self, mass: int, is_shine: bool) -> int:
        if mass == len(self.board) - 1:
            return 0

        if not is_shine:
            return 0

        if self.board[mass] == is_shine:
            return 1 + self.calc_move_times(mass+1, not self.board[mass+1])
        else:
            return 1 + self.calc_move_times(mass+1, self.board[mass+1])


def main():
    N = int(input())
    A = list(map(int, input().split()))
    board = Board(A)
    print(sum(map(lambda arg: board.calc_move_times(arg[0], arg[1]),
                  (zip(reversed(range(N)), reversed(A))))))


if __name__ == "__main__":
    main()
0