結果

問題 No.314 ケンケンパ
ユーザー はむ吉🐹はむ吉🐹
提出日時 2015-12-25 20:31:52
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 430 ms / 1,000 ms
コード長 708 bytes
コンパイル時間 493 ms
コンパイル使用メモリ 11,900 KB
実行使用メモリ 25,552 KB
最終ジャッジ日時 2023-10-19 03:47:14
合計ジャッジ時間 3,083 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 426 ms
25,288 KB
testcase_01 AC 30 ms
10,196 KB
testcase_02 AC 30 ms
10,196 KB
testcase_03 AC 30 ms
10,196 KB
testcase_04 AC 30 ms
10,196 KB
testcase_05 AC 30 ms
10,196 KB
testcase_06 AC 30 ms
10,196 KB
testcase_07 AC 30 ms
10,196 KB
testcase_08 AC 30 ms
10,196 KB
testcase_09 AC 30 ms
10,196 KB
testcase_10 AC 31 ms
10,196 KB
testcase_11 AC 31 ms
10,200 KB
testcase_12 AC 30 ms
10,200 KB
testcase_13 AC 31 ms
10,204 KB
testcase_14 AC 34 ms
10,276 KB
testcase_15 AC 35 ms
10,292 KB
testcase_16 AC 42 ms
10,384 KB
testcase_17 AC 72 ms
11,704 KB
testcase_18 AC 222 ms
17,640 KB
testcase_19 AC 430 ms
25,552 KB
権限があれば一括ダウンロードができます

ソースコード

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, max_number, one=ONE, two=TWO, three=THREE, modulus=MODULUS):
        self.modulus = modulus
        self.memo = array.array("q", [UNDETERMINED] * (max(4, max_number + 1)))
        self.memo[1] = one
        self.memo[2] = two
        self.memo[3] = three

    def count_courses(self, n):
        for x in range(4, n + 1):
            self.memo[x] = (self.memo[x - 2] + self.memo[x - 3]) % self.modulus
        return self.memo[n]


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