Submission #42917943


Source Code Expand

N, M = map(int, input().split())
MOD = 998244353

ans = [0] * (N + 1)
ans[1] = M
ans[2] = (M * (M - 1)) % MOD
for n in range(3, N + 1):
    ans[n] = (M * pow(M - 1, n - 1, MOD) % MOD - ans[n - 1]) % MOD
print(ans[-1])

Submission Info

Submission Time
Task E - Distinct Adjacent
User terrafarm
Language PyPy3 (7.3.0)
Score 475
Code Size 227 Byte
Status AC
Exec Time 387 ms
Memory 71596 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 475 / 475
Status
AC × 3
AC × 24
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All hand_01.txt, hand_02.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
hand_01.txt AC 212 ms 67376 KiB
hand_02.txt AC 146 ms 66064 KiB
random_01.txt AC 383 ms 71312 KiB
random_02.txt AC 156 ms 66308 KiB
random_03.txt AC 106 ms 65224 KiB
random_04.txt AC 153 ms 66420 KiB
random_05.txt AC 387 ms 71448 KiB
random_06.txt AC 346 ms 70868 KiB
random_07.txt AC 121 ms 65324 KiB
random_08.txt AC 62 ms 64100 KiB
random_09.txt AC 384 ms 71324 KiB
random_10.txt AC 78 ms 64668 KiB
random_11.txt AC 152 ms 66412 KiB
random_12.txt AC 55 ms 63676 KiB
random_13.txt AC 381 ms 71596 KiB
random_14.txt AC 331 ms 70448 KiB
random_15.txt AC 345 ms 70648 KiB
random_16.txt AC 315 ms 69828 KiB
random_17.txt AC 48 ms 61828 KiB
random_18.txt AC 382 ms 71452 KiB
random_19.txt AC 48 ms 61804 KiB
sample_01.txt AC 45 ms 61796 KiB
sample_02.txt AC 49 ms 61784 KiB
sample_03.txt AC 380 ms 71380 KiB