Submission #5396246


Source Code Expand

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 1000005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
const int MOD = 1000000007;
int N,M;
int dp[305][305][305];
int inc(int a,int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
    return 1LL * a * b % MOD;
}
void update(int &x,int y) {
    x = inc(x,y);
}
void Solve() {
    read(N);read(M);
    dp[0][1][1] = 1;
    for(int i = 0 ; i < M ; ++i) {
	for(int j = 1 ; j <= i + 1 ; ++j) {
	    for(int k = 1 ; k <= i + 1 ; ++k) {
		if(!dp[i][j][k]) continue;
		update(dp[i + 1][j][k + 1],mul(dp[i][j][k],N - k));
		update(dp[i + 1][k][k],mul(dp[i][j][k],j));
		update(dp[i + 1][j][k],mul(dp[i][j][k],k - j));
	    }
	}
    }
    out(dp[M][N][N]);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}

Submission Info

Submission Time
Task F - Road of the King
User sigongzi
Language C++14 (GCC 5.4.1)
Score 1000
Code Size 1517 Byte
Status AC
Exec Time 64 ms
Memory 108800 KB

Judge Result

Set Name sample all
Score / Max Score 0 / 0 1000 / 1000
Status
AC × 3
AC × 16
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, sample-01.txt, sample-02.txt, sample-03.txt
Case Name Status Exec Time Memory
01-01.txt AC 1 ms 256 KB
01-02.txt AC 1 ms 256 KB
01-03.txt AC 30 ms 108800 KB
01-04.txt AC 1 ms 256 KB
01-05.txt AC 30 ms 108800 KB
01-06.txt AC 38 ms 108800 KB
01-07.txt AC 64 ms 108800 KB
01-08.txt AC 64 ms 108800 KB
01-09.txt AC 64 ms 108800 KB
01-10.txt AC 64 ms 108800 KB
sample-01.txt AC 1 ms 256 KB
sample-02.txt AC 48 ms 108800 KB
sample-03.txt AC 17 ms 53504 KB