Submission #992870


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

const int MOD=1000000007;
int N, M;
int dp[301][301][305];

void addmod(int& x, int v)
{
    x+=v;
    if(x>=MOD)
        x-=MOD;
}

int rec(int m, int n, int l)
{
    if(m==M)
        return n==N && l==N+1;
    int& ret=dp[m][n][l];
    if(ret!=-1)
        return ret;
    ret=0;
    // last town not visit, or something before that
    addmod(ret, 1LL*rec(m+1, n, n+1)*(l-1)%MOD);
    // nothing special
    addmod(ret, 1LL*rec(m+1, n, l)*(n-l+1)%MOD);
    // new explore
    if(n<N)
        addmod(ret, 1LL*rec(m+1, n+1, l)*(N-n)%MOD);
    return ret;
}

int main()
{
    memset(dp, -1, sizeof dp);
    scanf("%d%d", &N, &M);
    int ans=rec(0, 1, 2);
    printf("%d\n", ans);
    return 0;
}

Submission Info

Submission Time
Task F - Road of the King
User FatalEagle
Language C++14 (GCC 5.4.1)
Score 1000
Code Size 785 Byte
Status AC
Exec Time 218 ms
Memory 108288 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:37:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &N, &M);
                          ^

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 104 ms 108160 KB
01-02.txt AC 104 ms 108160 KB
01-03.txt AC 104 ms 108160 KB
01-04.txt AC 104 ms 108160 KB
01-05.txt AC 105 ms 108160 KB
01-06.txt AC 137 ms 108288 KB
01-07.txt AC 218 ms 108160 KB
01-08.txt AC 214 ms 108160 KB
01-09.txt AC 214 ms 108160 KB
01-10.txt AC 214 ms 108160 KB
sample-01.txt AC 103 ms 108160 KB
sample-02.txt AC 176 ms 108160 KB
sample-03.txt AC 118 ms 108160 KB