結果

問題 No.1847 Good Sequence
ユーザー chineristACchineristAC
提出日時 2022-02-18 22:54:21
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 344 ms / 3,000 ms
コード長 2,161 bytes
コンパイル時間 300 ms
コンパイル使用メモリ 87,008 KB
実行使用メモリ 81,492 KB
最終ジャッジ日時 2023-09-11 19:55:46
合計ジャッジ時間 8,088 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
74,604 KB
testcase_01 AC 131 ms
79,256 KB
testcase_02 AC 143 ms
79,160 KB
testcase_03 AC 121 ms
74,556 KB
testcase_04 AC 124 ms
78,492 KB
testcase_05 AC 125 ms
79,144 KB
testcase_06 AC 125 ms
79,220 KB
testcase_07 AC 127 ms
79,132 KB
testcase_08 AC 127 ms
79,172 KB
testcase_09 AC 130 ms
79,176 KB
testcase_10 AC 119 ms
74,504 KB
testcase_11 AC 118 ms
74,536 KB
testcase_12 AC 128 ms
78,932 KB
testcase_13 AC 126 ms
79,408 KB
testcase_14 AC 128 ms
79,252 KB
testcase_15 AC 129 ms
79,556 KB
testcase_16 AC 135 ms
79,756 KB
testcase_17 AC 130 ms
79,440 KB
testcase_18 AC 137 ms
79,228 KB
testcase_19 AC 136 ms
80,072 KB
testcase_20 AC 128 ms
79,152 KB
testcase_21 AC 247 ms
81,164 KB
testcase_22 AC 159 ms
81,492 KB
testcase_23 AC 129 ms
79,212 KB
testcase_24 AC 124 ms
79,480 KB
testcase_25 AC 175 ms
81,200 KB
testcase_26 AC 124 ms
79,140 KB
testcase_27 AC 138 ms
79,108 KB
testcase_28 AC 161 ms
80,972 KB
testcase_29 AC 128 ms
79,252 KB
testcase_30 AC 138 ms
80,176 KB
testcase_31 AC 191 ms
81,024 KB
testcase_32 AC 166 ms
81,104 KB
testcase_33 AC 246 ms
80,948 KB
testcase_34 AC 122 ms
79,208 KB
testcase_35 AC 125 ms
79,204 KB
testcase_36 AC 238 ms
81,304 KB
testcase_37 AC 211 ms
80,944 KB
testcase_38 AC 116 ms
74,464 KB
testcase_39 AC 118 ms
74,548 KB
testcase_40 AC 344 ms
81,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,random,bisect
from collections import deque,defaultdict
from heapq import heapify,heappop,heappush
from itertools import permutations
from math import log,gcd

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

mod = 10**9 + 7

def mat_mul(X,Y):
    n,m = len(X),len(Y[0])
    res = [[0 for j in range(m)] for i in range(n)]
    for i in range(n):
        for j in range(m):
            for k in range(len(Y)):
                res[i][j] += X[i][k] * Y[k][j]
                res[i][j] %= mod
    return res

L,N,M = mi()
K = li()

cond = []
cond_to_i = {}
t = 0
for i in range(1,N+1):
    if i in K:
        for j in range(1,i+2):
            cond.append((i,j))
            cond_to_i[i,j] = t
            t += 1
    else:
        cond.append((i,1))
        cond_to_i[i,1] = t
        t += 1
cond.append((-1,-1))
cond_to_i[-1,-1] = t

NN = len(cond)
A = [[0 for j in range(NN)] for i in range(NN)]

for i,j in cond:
    for n in range(1,N+1):
        if (i,j)==(-1,-1):
            ni,nj = (-1,-1)
        else:
            if i in K:
                if j==i+1:
                    if n==i:
                        ni,nj = i,j
                    else:
                        ni,nj = n,1
                elif j==i:
                    if n==i:
                        ni,nj = i,j+1
                    else:
                        ni,nj = -1,-1
                else:
                    if n==i:
                        ni,nj = i,j+1
                    else:
                        ni,nj = n,1
            
            else:
                if n==i:
                    ni,nj = i,j
                else:
                    ni,nj = n,1
        
        x,y = cond_to_i[i,j],cond_to_i[ni,nj]
        A[y][x] += 1

E = [[0]] * NN
for i in range(1,N+1):
    t = cond_to_i[i,1]
    E[t] = [1]

L -= 1
while L:
    if L & 1:
        E = mat_mul(A,E)
    A = mat_mul(A,A)
    L >>= 1

res = 0
for i,j in cond:
    t = cond_to_i[i,j]
    if (i,j)==(-1,-1):
        res += E[t][0]
    elif i in K and j==i:
        res += E[t][0]
    res %= mod

    #print(i,j,E[t][0])

print(res)

            


0