結果

問題 No.1758 Lazy Segment Tree...?
ユーザー NyaanNyaanNyaanNyaan
提出日時 2021-10-16 01:38:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 5,421 ms / 8,000 ms
コード長 948 bytes
コンパイル時間 2,236 ms
コンパイル使用メモリ 86,468 KB
実行使用メモリ 83,240 KB
最終ジャッジ日時 2023-09-01 23:34:09
合計ジャッジ時間 80,635 ms
ジャッジサーバーID
(参考情報)
judge11 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,156 KB
testcase_01 AC 75 ms
70,900 KB
testcase_02 AC 201 ms
78,736 KB
testcase_03 AC 73 ms
71,244 KB
testcase_04 AC 73 ms
71,316 KB
testcase_05 AC 76 ms
71,084 KB
testcase_06 AC 88 ms
76,236 KB
testcase_07 AC 152 ms
77,484 KB
testcase_08 AC 139 ms
77,416 KB
testcase_09 AC 188 ms
78,480 KB
testcase_10 AC 160 ms
77,672 KB
testcase_11 AC 182 ms
78,472 KB
testcase_12 AC 185 ms
78,352 KB
testcase_13 AC 191 ms
78,412 KB
testcase_14 AC 150 ms
78,100 KB
testcase_15 AC 191 ms
79,312 KB
testcase_16 AC 174 ms
77,904 KB
testcase_17 AC 196 ms
77,952 KB
testcase_18 AC 156 ms
77,408 KB
testcase_19 AC 166 ms
77,532 KB
testcase_20 AC 169 ms
77,672 KB
testcase_21 AC 4,490 ms
81,036 KB
testcase_22 AC 3,573 ms
80,176 KB
testcase_23 AC 4,678 ms
81,292 KB
testcase_24 AC 4,168 ms
81,604 KB
testcase_25 AC 3,030 ms
80,612 KB
testcase_26 AC 4,762 ms
82,588 KB
testcase_27 AC 3,323 ms
80,916 KB
testcase_28 AC 4,596 ms
81,776 KB
testcase_29 AC 4,537 ms
81,156 KB
testcase_30 AC 5,035 ms
81,752 KB
testcase_31 AC 3,527 ms
81,264 KB
testcase_32 AC 4,115 ms
81,604 KB
testcase_33 AC 3,988 ms
80,852 KB
testcase_34 AC 3,637 ms
80,744 KB
testcase_35 AC 2,714 ms
80,068 KB
testcase_36 AC 5,421 ms
82,940 KB
testcase_37 AC 5,063 ms
83,240 KB
testcase_38 AC 4,485 ms
82,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod=998244353
def modpow(a,b,m):
  res=1
  while b:
    if b%2:
      res*=a
      res%=m
    a*=a
    a%=m
    b//=2
  return res
def prodmat(a,b):
  x,y,z=len(a),len(b[0]),len(b)
  c=[[0 for i in range(y)] for j in range(x)]
  for i in range(x):
    for j in range(y):
      for k in range(z):
        c[i][k]+=a[i][j]*b[j][k]
        c[i][k]%=mod
  return c
def powermat(a,k):
  x=len(a)
  b=[[0 for i in range(x)] for j in range(x)]
  for i in range(x):
    b[i][i]=1
  while k:
    if k%2:
      b=prodmat(b,a)
    a=prodmat(a,a)
    k//=2
  return b
n,q=map(int,input().split())
ans=0
for i in range(1,n):
  x=i*(n-i+1)
  y=n*(n+1)//2-x
  z=(n-i)*(n-i+1)*(n-i+2)//6
  x%=mod
  y%=mod
  z%=mod
  a=[[0 for i in range(3)] for j in range(3)]
  a[1][2]+=z
  a[2][2]+=n*(n+1)
  a[0][0]+=y
  a[0][0]+=n*(n+1)//2%mod
  a[1][1]+=y
  a[1][1]+=n*(n+1)//2%mod
  a[1][0]+=x
  a[0][1]+=x
  a=powermat(a,q)
  ans+=a[0][2]
print(ans*modpow(2,mod-2,mod)%mod)
0