Submission #42931163


Source Code Expand

import std;

void read(T...)(string S, ref T args) {
    auto buf = S.split;
    foreach (i, ref arg; args) {
        arg = buf[i].to!(typeof(arg));
    }
}

void main () {
    int N, M; readln.read(N, M);
    solve(N, M);
}

void solve (int N, int M) {
    const MOD = 998244353;
    long[][] dp = new long[][](N, 2);
    // dp[i][j] := 状態jでi人目に行く場合の数 (j=0は最初の人と同じ j=1は最初の人と違う数字)

    // initialize
    dp[0][0] = M;
    dp[0][1] = 0;

    foreach (i; 1..N) {
        dp[i][0] = dp[i-1][1];
        dp[i][1] = (M-1) * dp[i-1][0] + (M-2) * dp[i-1][1];
        dp[i][] %= MOD;
    }

    writeln(dp[$-1][1]);
}

Submission Info

Submission Time
Task E - Distinct Adjacent
User InTheBloom
Language D (DMD 2.091.0)
Score 475
Code Size 701 Byte
Status AC
Exec Time 156 ms
Memory 51352 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 79 ms 25540 KiB
hand_02.txt AC 56 ms 18168 KiB
random_01.txt AC 154 ms 51200 KiB
random_02.txt AC 63 ms 20112 KiB
random_03.txt AC 39 ms 12704 KiB
random_04.txt AC 63 ms 19344 KiB
random_05.txt AC 152 ms 51348 KiB
random_06.txt AC 143 ms 46796 KiB
random_07.txt AC 45 ms 14824 KiB
random_08.txt AC 20 ms 5936 KiB
random_09.txt AC 151 ms 51204 KiB
random_10.txt AC 28 ms 8640 KiB
random_11.txt AC 60 ms 19796 KiB
random_12.txt AC 9 ms 4264 KiB
random_13.txt AC 152 ms 51264 KiB
random_14.txt AC 133 ms 44484 KiB
random_15.txt AC 140 ms 46632 KiB
random_16.txt AC 130 ms 42392 KiB
random_17.txt AC 2 ms 3544 KiB
random_18.txt AC 156 ms 51352 KiB
random_19.txt AC 2 ms 3540 KiB
sample_01.txt AC 3 ms 3512 KiB
sample_02.txt AC 2 ms 3532 KiB
sample_03.txt AC 150 ms 50776 KiB