結果
問題 | No.1847 Good Sequence |
ユーザー | chineristAC |
提出日時 | 2022-02-18 22:54:21 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 238 ms / 3,000 ms |
コード長 | 2,161 bytes |
コンパイル時間 | 127 ms |
コンパイル使用メモリ | 82,124 KB |
実行使用メモリ | 77,312 KB |
最終ジャッジ日時 | 2024-06-29 09:41:12 |
合計ジャッジ時間 | 4,064 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
56,576 KB |
testcase_01 | AC | 55 ms
65,792 KB |
testcase_02 | AC | 66 ms
70,400 KB |
testcase_03 | AC | 43 ms
56,320 KB |
testcase_04 | AC | 50 ms
62,336 KB |
testcase_05 | AC | 49 ms
64,512 KB |
testcase_06 | AC | 46 ms
63,872 KB |
testcase_07 | AC | 50 ms
65,024 KB |
testcase_08 | AC | 48 ms
65,024 KB |
testcase_09 | AC | 51 ms
66,028 KB |
testcase_10 | AC | 41 ms
56,192 KB |
testcase_11 | AC | 40 ms
56,704 KB |
testcase_12 | AC | 49 ms
63,488 KB |
testcase_13 | AC | 49 ms
64,896 KB |
testcase_14 | AC | 49 ms
66,688 KB |
testcase_15 | AC | 50 ms
66,432 KB |
testcase_16 | AC | 59 ms
68,864 KB |
testcase_17 | AC | 58 ms
67,332 KB |
testcase_18 | AC | 60 ms
69,376 KB |
testcase_19 | AC | 59 ms
68,608 KB |
testcase_20 | AC | 54 ms
65,664 KB |
testcase_21 | AC | 161 ms
77,184 KB |
testcase_22 | AC | 82 ms
77,176 KB |
testcase_23 | AC | 54 ms
65,792 KB |
testcase_24 | AC | 49 ms
63,744 KB |
testcase_25 | AC | 101 ms
77,184 KB |
testcase_26 | AC | 50 ms
64,000 KB |
testcase_27 | AC | 63 ms
70,784 KB |
testcase_28 | AC | 91 ms
76,672 KB |
testcase_29 | AC | 57 ms
65,792 KB |
testcase_30 | AC | 66 ms
71,296 KB |
testcase_31 | AC | 111 ms
77,312 KB |
testcase_32 | AC | 98 ms
76,928 KB |
testcase_33 | AC | 163 ms
76,928 KB |
testcase_34 | AC | 50 ms
64,000 KB |
testcase_35 | AC | 49 ms
64,000 KB |
testcase_36 | AC | 155 ms
76,928 KB |
testcase_37 | AC | 127 ms
77,184 KB |
testcase_38 | AC | 42 ms
56,064 KB |
testcase_39 | AC | 40 ms
55,936 KB |
testcase_40 | AC | 238 ms
77,192 KB |
ソースコード
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)