結果

問題 No.541 3 x N グリッド上のサイクルの個数
ユーザー naoya_tnaoya_t
提出日時 2017-07-01 10:00:15
言語 Python2
(2.7.18)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 1,375 bytes
コンパイル時間 59 ms
コンパイル使用メモリ 6,912 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 09:52:39
合計ジャッジ時間 2,779 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
6,812 KB
testcase_01 AC 13 ms
6,944 KB
testcase_02 AC 13 ms
6,940 KB
testcase_03 AC 12 ms
6,940 KB
testcase_04 AC 11 ms
6,944 KB
testcase_05 AC 12 ms
6,940 KB
testcase_06 AC 12 ms
6,944 KB
testcase_07 AC 12 ms
6,944 KB
testcase_08 AC 12 ms
6,940 KB
testcase_09 AC 18 ms
6,940 KB
testcase_10 AC 18 ms
6,944 KB
testcase_11 AC 18 ms
6,944 KB
testcase_12 AC 17 ms
6,940 KB
testcase_13 AC 18 ms
6,944 KB
testcase_14 AC 18 ms
6,940 KB
testcase_15 AC 17 ms
6,944 KB
testcase_16 AC 17 ms
6,944 KB
testcase_17 AC 17 ms
6,940 KB
testcase_18 AC 17 ms
6,944 KB
testcase_19 AC 23 ms
6,944 KB
testcase_20 AC 23 ms
6,940 KB
testcase_21 AC 25 ms
6,944 KB
testcase_22 AC 24 ms
6,940 KB
testcase_23 AC 26 ms
6,944 KB
testcase_24 AC 24 ms
6,940 KB
testcase_25 AC 25 ms
6,944 KB
testcase_26 AC 25 ms
6,940 KB
testcase_27 AC 25 ms
6,944 KB
testcase_28 AC 25 ms
6,940 KB
testcase_29 AC 12 ms
6,944 KB
testcase_30 AC 12 ms
6,940 KB
testcase_31 AC 12 ms
6,944 KB
testcase_32 AC 12 ms
6,944 KB
testcase_33 AC 12 ms
6,944 KB
testcase_34 AC 12 ms
6,944 KB
testcase_35 AC 12 ms
6,940 KB
testcase_36 AC 12 ms
6,944 KB
testcase_37 AC 13 ms
6,944 KB
testcase_38 AC 12 ms
6,940 KB
testcase_39 AC 13 ms
6,940 KB
testcase_40 AC 17 ms
6,944 KB
testcase_41 AC 18 ms
6,940 KB
testcase_42 AC 18 ms
6,940 KB
testcase_43 AC 18 ms
6,940 KB
testcase_44 AC 17 ms
6,940 KB
testcase_45 AC 18 ms
6,944 KB
testcase_46 AC 18 ms
6,940 KB
testcase_47 AC 18 ms
6,940 KB
testcase_48 AC 18 ms
6,940 KB
testcase_49 AC 18 ms
6,940 KB
testcase_50 AC 19 ms
6,944 KB
testcase_51 AC 25 ms
6,940 KB
testcase_52 AC 24 ms
6,940 KB
testcase_53 AC 24 ms
6,940 KB
testcase_54 AC 25 ms
6,944 KB
testcase_55 AC 25 ms
6,940 KB
testcase_56 AC 25 ms
6,940 KB
testcase_57 AC 25 ms
6,940 KB
testcase_58 AC 24 ms
6,940 KB
testcase_59 AC 26 ms
6,944 KB
testcase_60 AC 25 ms
6,940 KB
testcase_61 AC 26 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 1000000007

N = int(raw_input().rstrip())


def zero(R, C):
    return [[0] * C for i in range(R)]


def eye(n):
    A = zero(n, n)
    for i in range(n):
        A[i][i] = 1
    return A


I = eye(10)

A = [[1, 1, 1, 0, 0, 0,  1, 0,  0, 1],  # 0..
     [1, 1, 1, 1, 1, 0,  0, 0,  0, 1],  # 01.
     [1, 1, 1, 1, 1, 1,  0, 1,  0, 1],  # 012
     [0, 1, 1, 1, 1, 0,  0, 0,  0, 1],  # .1.
     [0, 1, 1, 1, 1, 1,  0, 0,  0, 1],  # .12
     [0, 0, 1, 0, 1, 1,  1, 0,  0, 1],  # ..2
     [0, 0, 1, 0, 0, 0,  1, 0,  0, 0],  # 0.2 <closed>
     [1, 0, 0, 0, 0, 1,  0, 1,  0, 1],  # 0.2 <open>

     [1, 1, 1, 1, 1, 1,  1, 0,  1, 0],  # stop here
     [0, 0, 0, 0, 0, 0,  0, 0,  0, 1]]  # start here


def mul(A, B):
    R, C, X = len(A), len(B[0]), len(B)
    # assert len(A[0]) == len(B)
    D = zero(R, C)
    for r in range(R):
        for c in range(C):
            k = 0
            for i in range(X):
                k += A[r][i] * B[i][c]
            D[r][c] = k % MOD
    return D


def mul1(A, b):
    Ab = mul(A, [[bi] for bi in b])
    return [r[0] for r in Ab]


def pow(A, n):
    if n == 0:
        return I
    elif n == 1:
        return A
    B = pow(mul(A, A), n/2)
    if n % 2 == 1:
        B = mul(B, A)
    return B


X = pow(A, N+1)

# for r in X: print r
x = mul1(X, [0, 0, 0, 0, 0, 0, 0, 0, 0, 1])
# print "x=", x, sum(x[:7]) % MOD

print x[8] % MOD
0