結果

問題 No.314 ケンケンパ
ユーザー はむ吉🐹はむ吉🐹
提出日時 2015-12-18 21:19:30
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 892 bytes
コンパイル時間 368 ms
コンパイル使用メモリ 10,912 KB
実行使用メモリ 24,304 KB
最終ジャッジ日時 2023-10-14 14:02:39
合計ジャッジ時間 1,802 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 16 ms
8,664 KB
testcase_02 AC 17 ms
8,668 KB
testcase_03 AC 17 ms
8,600 KB
testcase_04 AC 17 ms
8,632 KB
testcase_05 AC 16 ms
8,568 KB
testcase_06 AC 16 ms
8,560 KB
testcase_07 AC 17 ms
8,612 KB
testcase_08 AC 16 ms
8,696 KB
testcase_09 AC 16 ms
8,552 KB
testcase_10 AC 15 ms
8,584 KB
testcase_11 AC 17 ms
8,724 KB
testcase_12 AC 18 ms
8,724 KB
testcase_13 AC 17 ms
8,764 KB
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array

UNDETERMINED = -1
MODULUS = 10 ** 9 + 7
ONE = 1
TWO = 2
THREE = 2


class Kenkenpa(object):

    def __init__(self, number, one=ONE, two=TWO, three=THREE, modulus=MODULUS):
        self.number = number
        self.modulus = modulus
        self.memo = array.array("q", [UNDETERMINED] * (max(4, number + 1)))
        self.memo[1] = one
        self.memo[2] = two
        self.memo[3] = three

    def count_courses(self, n=None):
        if n is None:
            n = self.number
        m = self.memo[n]
        if m != UNDETERMINED:
            return m
        else:
            result = (self.count_courses(n - 2) +
                      self.count_courses(n - 3)) % self.modulus
            self.memo[n] = result
            return result


if __name__ == "__main__":
    print(Kenkenpa(number=int(input())).count_courses())
0