Submission #1891540


Source Code Expand

#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<stack>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)

#define MOD 1000000007

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

ll dp[350][350][350];

int main()
{
	int n,m;cin >> n >> m;
	
	dp[0][n-1][1] = 1;
	
	REP(i,m)
	{
		REP(j,n+1)
		{
			REP(k,n+1)
			{
				if(j > 0)
				{
					dp[i+1][j-1][k] = (dp[i+1][j-1][k] + j*dp[i][j][k])%MOD;
				}
				
				if(j+k < n)
				{
					dp[i+1][j][n-j] = (dp[i+1][j][n-j] + k*dp[i][j][k])%MOD;
					dp[i+1][j][k] = (dp[i+1][j][k] + (n-j-k)*dp[i][j][k])%MOD;
				}
				else
				{
					dp[i+1][j][k] = (dp[i+1][j][k] + k*dp[i][j][k])%MOD;
				}
			}
		}
//		SHOW2d(dp[i+1],n+1,n+1);
	}

	cout << dp[m][0][n] << endl;
	
	
	return 0;
}

Submission Info

Submission Time
Task F - Road of the King
User seica
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1667 Byte
Status MLE
Exec Time 191 ms
Memory 287872 KB

Judge Result

Set Name sample all
Score / Max Score 0 / 0 0 / 1000
Status
AC × 2
MLE × 1
AC × 7
MLE × 9
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 MLE 93 ms 286976 KB
01-04.txt AC 2 ms 1024 KB
01-05.txt MLE 57 ms 286976 KB
01-06.txt MLE 69 ms 287360 KB
01-07.txt MLE 182 ms 287872 KB
01-08.txt MLE 189 ms 287872 KB
01-09.txt MLE 190 ms 287872 KB
01-10.txt MLE 191 ms 287872 KB
sample-01.txt AC 1 ms 2304 KB
sample-02.txt MLE 91 ms 287488 KB
sample-03.txt AC 96 ms 144512 KB