Submission #1001470


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 = new long[][][](M+1, N+1, N+1);
    dp[0][1][1] = 1;
    foreach(i; 0..M) foreach(j; 0..N+1) foreach(k; 0..N+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) @property {
    v1 = (v1 + v2)%MOD;
}

Submission Info

Submission Time
Task F - Road of the King
User arkark
Language D (DMD64 v2.070.1)
Score 0
Code Size 1231 Byte
Status MLE
Exec Time 2007 ms
Memory 365564 KB

Judge Result

Set Name sample all
Score / Max Score 0 / 0 0 / 1000
Status
AC × 3
AC × 9
MLE × 4
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 3 ms 256 KB
01-03.txt AC 3 ms 380 KB
01-04.txt AC 11 ms 2684 KB
01-05.txt AC 5 ms 764 KB
01-06.txt AC 144 ms 28924 KB
01-07.txt MLE 1883 ms 352380 KB
01-08.txt MLE 1978 ms 363132 KB
01-09.txt MLE 1993 ms 364412 KB
01-10.txt MLE 2007 ms 365564 KB
sample-01.txt AC 3 ms 256 KB
sample-02.txt AC 467 ms 95612 KB
sample-03.txt AC 1007 ms 183548 KB