Submission #2663590
Source Code Expand
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
using namespace std;
using Int = long long;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<55)+1e9; // ~ 3.6 * 1e16
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
using T = tuple<Int,Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
ostream& operator<<(ostream& o,T t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){Int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){Int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}
const Int N = 310;
Int n, m;
int mem[N][N][N];
bool used[N][N][N];
Int dfs(Int pos, Int num, Int cnt){
if(pos == n-1 && num == n-1 && cnt == m) return 1;
if(pos == n || cnt == m) return 0;
if(used[pos][num][cnt]) return mem[pos][num][cnt];
used[pos][num][cnt] = 1;
// つなぐ
Int a = dfs(pos, pos, cnt+1) * (num+1);
// ループ
Int b = dfs(pos, num, cnt + 1) * (pos - num);
// 進む
Int c = dfs(pos + 1, num, cnt + 1);
Int res = (a + b + c) % mod;
return mem[pos][num][cnt] = res;
}
signed main(){
cin.tie(0);
ios_base::sync_with_stdio(0);
cout << fixed << setprecision(12);
cin>>n>>m;
Int k = 1;
for(Int i = n-1;i>=1;i--) k = k * i % mod;
Int ans = dfs(0, 0, 0) * k % mod;
cout<<ans<<endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
F - Road of the King |
User |
haji |
Language |
C++14 (GCC 5.4.1) |
Score |
1000 |
Code Size |
2266 Byte |
Status |
AC |
Exec Time |
135 ms |
Memory |
141696 KB |
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 |
2 ms |
2304 KB |
01-02.txt |
AC |
2 ms |
2304 KB |
01-03.txt |
AC |
2 ms |
2304 KB |
01-04.txt |
AC |
2 ms |
2304 KB |
01-05.txt |
AC |
2 ms |
4480 KB |
01-06.txt |
AC |
30 ms |
43392 KB |
01-07.txt |
AC |
133 ms |
137600 KB |
01-08.txt |
AC |
135 ms |
139648 KB |
01-09.txt |
AC |
135 ms |
141696 KB |
01-10.txt |
AC |
135 ms |
141696 KB |
sample-01.txt |
AC |
2 ms |
2304 KB |
sample-02.txt |
AC |
66 ms |
70016 KB |
sample-03.txt |
AC |
27 ms |
70016 KB |