Submission #6775383
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define p (int)(1e9 + 7)
int MOD(int a){
return (a %= p) >= 0 ? a : a + p;
}
int fact(int N){
if(N == 0){
return 1;
}
else{
return MOD(N * fact(N - 1));
}
}
signed main(){
int N, M, i, j, k;
scanf("%lld%lld", &N, &M);
vector<vector<vector<int>>> dp(M + 1, vector<vector<int>>(N, vector<int>(N, 0)));
dp[0][0][0] = 1;
for(i = 0; i < M; i++){
for(j = 0; j < N; j++){
for(k = 0; k < N; k++){
// printf("dp[%lld, %lld, %lld] = %lld\n", i, j, k, dp[i][j][k]);
dp[i + 1][j][j] = MOD(dp[i + 1][j][j] + (k + 1) * dp[i][j][k]);
if(k < j){
dp[i + 1][j][k] = MOD(dp[i + 1][j][k] + (j - k) * dp[i][j][k]);
}
if(j < N - 1){
dp[i + 1][j + 1][k] = MOD(dp[i + 1][j + 1][k] + dp[i][j][k]);
}
}
}
}
printf("%lld\n", MOD(dp[M][N - 1][N - 1] * fact(N - 1)));
return 0;
}
Submission Info
Submission Time
2019-08-09 00:16:25+0900
Task
F - Road of the King
User
abc050
Language
C++14 (GCC 5.4.1)
Score
1000
Code Size
920 Byte
Status
AC
Exec Time
349 ms
Memory
216192 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:21:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld", &N, &M);
^
Judge Result
Set Name
sample
all
Score / Max Score
0 / 0
1000 / 1000
Status
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
1 ms
256 KB
01-04.txt
AC
3 ms
2432 KB
01-05.txt
AC
2 ms
640 KB
01-06.txt
AC
32 ms
19840 KB
01-07.txt
AC
326 ms
201472 KB
01-08.txt
AC
345 ms
213248 KB
01-09.txt
AC
347 ms
214016 KB
01-10.txt
AC
349 ms
216192 KB
sample-01.txt
AC
1 ms
256 KB
sample-02.txt
AC
89 ms
55168 KB
sample-03.txt
AC
175 ms
108928 KB