結果

問題 No.1897 Sum of 2nd Max
ユーザー ygd.ygd.
提出日時 2022-04-08 23:02:53
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 488 ms / 2,000 ms
コード長 1,412 bytes
コンパイル時間 490 ms
コンパイル使用メモリ 87,212 KB
実行使用メモリ 76,128 KB
最終ジャッジ日時 2023-08-19 01:36:01
合計ジャッジ時間 8,810 ms
ジャッジサーバーID
(参考情報)
judge9 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
71,136 KB
testcase_01 AC 61 ms
71,512 KB
testcase_02 AC 62 ms
71,348 KB
testcase_03 AC 393 ms
75,748 KB
testcase_04 AC 421 ms
75,948 KB
testcase_05 AC 230 ms
75,924 KB
testcase_06 AC 231 ms
76,040 KB
testcase_07 AC 286 ms
75,944 KB
testcase_08 AC 243 ms
76,028 KB
testcase_09 AC 411 ms
75,956 KB
testcase_10 AC 380 ms
75,924 KB
testcase_11 AC 383 ms
75,924 KB
testcase_12 AC 384 ms
75,752 KB
testcase_13 AC 398 ms
75,892 KB
testcase_14 AC 142 ms
76,128 KB
testcase_15 AC 145 ms
75,752 KB
testcase_16 AC 194 ms
75,640 KB
testcase_17 AC 171 ms
76,052 KB
testcase_18 AC 186 ms
76,048 KB
testcase_19 AC 61 ms
71,372 KB
testcase_20 AC 58 ms
71,348 KB
testcase_21 AC 60 ms
71,404 KB
testcase_22 AC 61 ms
71,356 KB
testcase_23 AC 62 ms
71,584 KB
testcase_24 AC 62 ms
71,060 KB
testcase_25 AC 59 ms
71,336 KB
testcase_26 AC 59 ms
71,432 KB
testcase_27 AC 61 ms
71,308 KB
testcase_28 AC 60 ms
71,060 KB
testcase_29 AC 62 ms
71,352 KB
testcase_30 AC 395 ms
76,044 KB
testcase_31 AC 413 ms
75,916 KB
testcase_32 AC 354 ms
75,892 KB
testcase_33 AC 488 ms
75,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
#input = sys.stdin.readline
#input = sys.stdin.buffer.readline #文字列はダメ
#sys.setrecursionlimit(1000000)
#import bisect
#import itertools
#import random
#from heapq import heapify, heappop, heappush
#from collections import defaultdict 
#from collections import deque
#import copy
#import math
#from functools import lru_cache
#@lru_cache(maxsize=None)
#MOD = pow(10,9) + 7
MOD = 998244353
#dx = [1,0,-1,0]
#dy = [0,1,0,-1]
#dx8 = [1,1,0,-1,-1,-1,0,1]
#dy8 = [0,1,1,1,0,-1,-1,-1]
#dx = [1,1,-1,-1]
#dy = [1,-1,1,-1]

def main():
    N,K = map(int,input().split())
    ans = 0
    for x in range(1,K+1):
        #print("X",x)
        val = 0
        #最大が異なる場合
        #最大の選び方がK-x通り、場所がN通り。
        temp = N * (K - x) %MOD
        #残りのN-1箇所は少なくともxを一つ含む。
        temp *= pow(x,N-1,MOD) - pow(x-1,N-1,MOD)
        val += temp
        val %= MOD
        #print(val)
        #最大が同じ場合(最大=x)
        #xを2個以上含む場合の数
        zero = pow(x-1,N,MOD) #0個含む
        one = N * pow(x-1,N-1,MOD) #1個含む
        temp = pow(x,N,MOD) - (zero + one)
        temp %= MOD
        val += temp
        val %= MOD
        #print(zero,one,temp)

        #xの和
        #print("VAL",val)
        ans += val * x %MOD
        ans %= MOD
    print(ans)

if __name__ == '__main__':
    main()
0