Submission #64345131


Source Code Expand

def solve():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    Mod = 998244353

    binom = [[0] * (K + 1) for _ in range(K + 1)]
    for n in range(K + 1):
        binom[n][0] = 1
        for r in range(1, K + 1):
            binom[n][r] = binom[n - 1][r - 1] + binom[n - 1][r]

    dp = [0] * (K + 1)
    dp_prev = [0] * (K + 1)
    power = [1] * (K + 1)
    ans = 0
    for p in range(N):
        dp_prev, dp = dp, dp_prev

        for k in range(K + 1):
            if k == 0:
                dp[k] = 1
            else:
                dp[k] = power[k] = A[p] * power[k - 1] % Mod

        for k in range(K + 1):
            dp[k] += sum((binom[k][m] * power[m]) % Mod * dp_prev[k - m] % Mod for m in range(k + 1))

        ans += dp[K]

    return ans % Mod

#==================================================
print(solve())

Submission Info

Submission Time
Task F - Range Power Sum
User Kazu1998k
Language Python (PyPy 3.10-v7.3.12)
Score 550
Code Size 898 Byte
Status AC
Exec Time 497 ms
Memory 115296 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 550 / 550
Status
AC × 3
AC × 44
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 03_minmax_00.txt, 03_minmax_01.txt, 03_minmax_02.txt, 03_minmax_03.txt, 03_minmax_04.txt, 03_minmax_05.txt, 03_minmax_06.txt, 03_minmax_07.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 54 ms 76492 KiB
00_sample_01.txt AC 55 ms 76372 KiB
00_sample_02.txt AC 53 ms 76500 KiB
01_random_00.txt AC 77 ms 83384 KiB
01_random_01.txt AC 148 ms 114808 KiB
01_random_02.txt AC 148 ms 114728 KiB
01_random_03.txt AC 151 ms 105764 KiB
01_random_04.txt AC 179 ms 114800 KiB
01_random_05.txt AC 180 ms 114944 KiB
01_random_06.txt AC 168 ms 105316 KiB
01_random_07.txt AC 208 ms 114780 KiB
01_random_08.txt AC 208 ms 114860 KiB
01_random_09.txt AC 186 ms 104680 KiB
01_random_10.txt AC 240 ms 115296 KiB
01_random_11.txt AC 239 ms 114868 KiB
01_random_12.txt AC 97 ms 85216 KiB
01_random_13.txt AC 277 ms 114736 KiB
01_random_14.txt AC 274 ms 115192 KiB
01_random_15.txt AC 186 ms 97360 KiB
01_random_16.txt AC 312 ms 115004 KiB
01_random_17.txt AC 312 ms 115292 KiB
01_random_18.txt AC 228 ms 100196 KiB
01_random_19.txt AC 352 ms 114860 KiB
01_random_20.txt AC 350 ms 114744 KiB
01_random_21.txt AC 229 ms 97600 KiB
01_random_22.txt AC 394 ms 114932 KiB
01_random_23.txt AC 394 ms 114800 KiB
01_random_24.txt AC 106 ms 84092 KiB
01_random_25.txt AC 438 ms 115136 KiB
01_random_26.txt AC 438 ms 114984 KiB
01_random_27.txt AC 360 ms 105080 KiB
01_random_28.txt AC 484 ms 114892 KiB
01_random_29.txt AC 497 ms 114704 KiB
02_random2_00.txt AC 485 ms 115260 KiB
02_random2_01.txt AC 488 ms 115008 KiB
02_random2_02.txt AC 486 ms 114848 KiB
03_minmax_00.txt AC 54 ms 76288 KiB
03_minmax_01.txt AC 54 ms 76504 KiB
03_minmax_02.txt AC 54 ms 76324 KiB
03_minmax_03.txt AC 54 ms 76304 KiB
03_minmax_04.txt AC 142 ms 111288 KiB
03_minmax_05.txt AC 149 ms 115008 KiB
03_minmax_06.txt AC 484 ms 111112 KiB
03_minmax_07.txt AC 489 ms 115076 KiB