結果
問題 | No.1516 simple 門松列 problem Re:MASTER |
ユーザー | googol_S0 |
提出日時 | 2021-05-21 22:22:50 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,525 bytes |
コンパイル時間 | 886 ms |
コンパイル使用メモリ | 82,464 KB |
実行使用メモリ | 78,552 KB |
最終ジャッジ日時 | 2024-10-10 09:09:53 |
合計ジャッジ時間 | 3,560 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
53,564 KB |
testcase_01 | AC | 64 ms
70,380 KB |
testcase_02 | AC | 179 ms
78,532 KB |
testcase_03 | AC | 39 ms
53,844 KB |
testcase_04 | AC | 38 ms
54,844 KB |
testcase_05 | AC | 50 ms
64,208 KB |
testcase_06 | AC | 159 ms
78,380 KB |
testcase_07 | AC | 92 ms
76,224 KB |
testcase_08 | AC | 145 ms
77,072 KB |
testcase_09 | AC | 38 ms
53,772 KB |
testcase_10 | AC | 48 ms
63,124 KB |
testcase_11 | AC | 38 ms
53,824 KB |
testcase_12 | AC | 38 ms
55,404 KB |
testcase_13 | AC | 37 ms
54,544 KB |
testcase_14 | AC | 190 ms
78,552 KB |
testcase_15 | AC | 155 ms
77,464 KB |
testcase_16 | AC | 138 ms
77,076 KB |
testcase_17 | AC | 126 ms
77,396 KB |
testcase_18 | WA | - |
testcase_19 | AC | 60 ms
68,088 KB |
testcase_20 | AC | 190 ms
78,492 KB |
testcase_21 | AC | 189 ms
78,176 KB |
ソースコード
N,K=map(int,input().split()) if K==3: if N==3: print(4,12) elif N==4: print(2,8) else: print(0,0) exit() def m(a,b): r=[[0]*len(b[0]) for i in range(len(a))] for i in range(len(a)): for k in range(len(b)): for j in range(len(b[0])): r[i][j]=(r[i][j]+a[i][k]*b[k][j])%mod return r def p(a,n): r=[[0]*len(a) for i in range(len(a))] b=[] for i in range(len(a)): r[i][i]=1 b.append(a[i][:]) l=n while l>0: if l&1: r=m(b,r) b=m(b,b) l>>=1 return r S='''1,998244352,1,0 1,998244350,4,0,4,0 2,998244348,12,998244346,24,998244350,18,0 2,998244346,22,998244341,88,4,152,16,96,0 3,998244341,44,998244303,254,998244269,734,998244310,1065,10,600,0 3,998244338,65,998244281,572,998244289,2620,452,6580,1284,8520,936,4320,0'''.split('\n') T='''2,998244350,4,998244350,2,998244352,0 2,998244348,12,998244341,24,998244329,16,998244321,0,998244337,0 4,998244339,44,998244266,196,998244037,456,998243626,588,998243303,396,998243480,108,998244029,0 4,998244337,64,998244224,404,998243615,1240,998241293,1712,998235977,160,998230497,998242305,998231937,998242817,998239745,0 6,998244320,160,998243845,1864,998239525,12468,998212995,52796,998099443,146556,997763045,265176,997105553,296964,996375964,177710,996230188,30300,996966253,998232353,997884353,0 6,998244314,220,998243594,3526,998234408,32144,998148073,179736,997544001,598472,994441937,857496,982989745,996484017,953551505,986209729,904320145,969293153,860989553,960141953,866399105,971201153,923755457,990157313,979581953,0'''.split('\n') mod=998244353 def solve1(N,K): DP1=[[[0]*K for i in range(K)] for j in range(N-1)] DP2=[[[0]*K for i in range(K)] for j in range(N-1)] for i in range(K): for j in range(K): if i!=j: DP1[0][i][j]=1 DP2[0][i][j]=i+j for i in range(N-2): for j in range(K): for k in range(K): for l in range(K): if (min(j,k,l)==k or max(j,k,l)==k) and j!=l and k!=l: DP1[i+1][k][l]+=DP1[i][j][k] DP2[i+1][k][l]+=DP2[i][j][k]+DP1[i][j][k]*l ANS1,ANS2=0,0 for i in range(K): for j in range(K): ANS1+=DP1[-1][i][j] ANS2+=DP2[-1][i][j] return ANS1 def solve2(N,K): DP1=[[[0]*K for i in range(K)] for j in range(N-1)] DP2=[[[0]*K for i in range(K)] for j in range(N-1)] for i in range(K): for j in range(K): if i!=j: DP1[0][i][j]=1 DP2[0][i][j]=i+j for i in range(N-2): for j in range(K): for k in range(K): for l in range(K): if (min(j,k,l)==k or max(j,k,l)==k) and j!=l and k!=l: DP1[i+1][k][l]+=DP1[i][j][k] DP2[i+1][k][l]+=DP2[i][j][k]+DP1[i][j][k]*l ANS1,ANS2=0,0 for i in range(K): for j in range(K): ANS1+=DP1[-1][i][j] ANS2+=DP2[-1][i][j] return ANS2 if N<=100: print(solve1(N,K)%mod,solve2(N,K)%mod) exit() M=K-4 X=[list(map(int,S[i].split(','))) for i in range(6)] Y=[list(map(int,T[i].split(','))) for i in range(6)] A=[[0]*len(X[M]) for i in range(len(X[M]))] for i in range(len(X[M])): A[i][-1]=solve1(len(X[M])-i+2,K) B=[[0]*len(X[M]) for i in range(len(X[M]))] for i in range(len(X[M])-1): B[i+1][i]=1 for i in range(len(X[M])): B[0][i]=X[M][i] ANS1=m(p(B,N-3),A)[-1][-1] A=[[0]*len(Y[M]) for i in range(len(Y[M]))] for i in range(len(Y[M])): A[i][-1]=solve2(len(Y[M])-i+2,K) B=[[0]*len(Y[M]) for i in range(len(Y[M]))] for i in range(len(Y[M])-1): B[i+1][i]=1 for i in range(len(Y[M])): B[0][i]=Y[M][i] print(ANS1,m(p(B,N-3),A)[-1][-1])