結果

問題 No.1897 Sum of 2nd Max
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2022-04-14 14:03:21
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,502 bytes
コンパイル時間 90 ms
コンパイル使用メモリ 10,960 KB
実行使用メモリ 51,880 KB
最終ジャッジ日時 2023-08-25 20:40:12
合計ジャッジ時間 36,752 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,232 KB
testcase_01 AC 16 ms
7,920 KB
testcase_02 AC 16 ms
8,208 KB
testcase_03 TLE -
testcase_04 TLE -
testcase_05 AC 1,113 ms
31,352 KB
testcase_06 AC 1,029 ms
21,208 KB
testcase_07 AC 1,470 ms
38,804 KB
testcase_08 AC 1,195 ms
30,752 KB
testcase_09 TLE -
testcase_10 TLE -
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 AC 533 ms
25,196 KB
testcase_15 AC 542 ms
25,164 KB
testcase_16 AC 798 ms
25,412 KB
testcase_17 AC 700 ms
25,192 KB
testcase_18 AC 789 ms
25,356 KB
testcase_19 AC 238 ms
31,692 KB
testcase_20 AC 243 ms
31,632 KB
testcase_21 AC 242 ms
31,656 KB
testcase_22 AC 243 ms
31,832 KB
testcase_23 AC 240 ms
31,672 KB
testcase_24 AC 16 ms
8,356 KB
testcase_25 AC 16 ms
8,360 KB
testcase_26 AC 16 ms
8,160 KB
testcase_27 AC 16 ms
8,292 KB
testcase_28 AC 16 ms
8,288 KB
testcase_29 AC 16 ms
8,188 KB
testcase_30 TLE -
testcase_31 TLE -
testcase_32 AC 1,705 ms
36,556 KB
testcase_33 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

mod=998244353
def solv(n,k):
    ans=0
    ary0=[0]*(k+1)
    ary1=[0]*(k+1)
    ary0[1]=1
    ary1[1]=(k-1)*n
    for i in range(2,k+1):
        # i以下のみで配列が作られている
        ary0[i]=pow(i,n,mod)-pow(i-1,n,mod)
        ary0[i]-=n*pow(i-1,n-1,mod)

        # iより大がちょうど一つあり、それ以外はi以下で配列が作られている
        if i<k:
            # al:iより大がちょうど一つ
            # mi:iより大がちょうど一つ、降順で2番目がi未満->iは含まれない
            al=(k-i)*n # iより大の取り方と場所
            al*=pow(i,n-1,mod) # i以下の数字
            mi=(k-i)*n # iより大の取り方と場所
            mi*=pow(i-1,n-1,mod) # i-1以下の数字
            ary1[i]=al-mi # iより大がちょうど一つで、降順で2番目がi

    ans=0
    for i in range(1,k+1):
        ans+=ary0[i]*i
        ans+=ary1[i]*i
        ans%=mod
    return ans
n,k=map(int,input().split())
# コンビネーション。あらかじめO(N)の計算をすることでのちの計算が早くなる
def cmb(n,r,mod):
  if (r<0 or r>n):
    return 0
  r=min(r,n-r)
  return (g1[n]*g2[r]*g2[n-r])%mod
g1=[1,1] # g1[i]=i! % mod :階乗
g2=[1,1] # g2[i]=(i!)^(-1) % mod :階乗の逆元
inverse=[0,1]
for i in range(2,n+1):
  g1.append((g1[-1]*i)%mod)
  inverse.append((-inverse[mod%i]*(mod//i))%mod)
  g2.append((g2[-1]*inverse[-1])%mod)
#print(solv_naive_ex(n,k))
#print(solv_naive(n,k))
print(solv(n,k))
0