Submission #1001476


Source Code Expand

import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
void times(alias fun)(int n) {
    foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(int n) {
    T[] res = new T[n];
    foreach(ref e; res) e = fun();
    return res;
}
// fold was added in D 2.071.0.
template fold(fun...) if (fun.length >= 1) {
    auto fold(R, S...)(R r, S seed) {
        static if (S.length < 2) {
            return reduce!fun(seed, r);
        } else {
            return reduce!fun(tuple(seed), r);
        }
    }
}

long MOD = 10^^9+7;
void main() {
    int N, M;
    readf("%d %d\n", &N, &M);

    long[][][] dp = (M+1).iota.map!(i => (min(i+1, N)+1).iota.map!(j => (j+1).iota.map!(k => 0L).array).array).array;
    dp[0][1][1] = 1;
    foreach(i; 0..M) foreach(j; 0..min(i+1, N)+1) foreach(k; 0..j+1) {
        if (j<N) dp[i+1][j+1][k].add(dp[i][j][k] * (N-j));
        dp[i+1][j][k].add(dp[i][j][k] * (j-k));
        dp[i+1][j][j].add(dp[i][j][k] * k);
    }
    dp.back.back.back.writeln;
}
void add(ref long v1, long v2) {
    v1 = (v1 + v2)%MOD;
}

Submission Info

Submission Time
Task F - Road of the King
User arkark
Language D (DMD64 v2.070.1)
Score 1000
Code Size 1298 Byte
Status AC
Exec Time 324 ms
Memory 54268 KB

Judge Result

Set Name sample all
Score / Max Score 0 / 0 1000 / 1000
Status
AC × 3
AC × 13
Set Name Test Cases
sample sample-01.txt, sample-02.txt, sample-03.txt
all sample-01.txt, sample-02.txt, sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt
Case Name Status Exec Time Memory
01-01.txt AC 3 ms 256 KB
01-02.txt AC 2 ms 256 KB
01-03.txt AC 3 ms 256 KB
01-04.txt AC 3 ms 256 KB
01-05.txt AC 4 ms 508 KB
01-06.txt AC 71 ms 12796 KB
01-07.txt AC 319 ms 53500 KB
01-08.txt AC 323 ms 54268 KB
01-09.txt AC 323 ms 54268 KB
01-10.txt AC 324 ms 54268 KB
sample-01.txt AC 3 ms 256 KB
sample-02.txt AC 165 ms 28412 KB
sample-03.txt AC 44 ms 7420 KB