Submission #992664


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;
ll dp[303][303][303];
ll mo=1000000007;
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	if(M<N) return _P("0\n");
	dp[0][1][1]=1; // as, tot
	FOR(i,M) {
		FOR(x,N+1) FOR(y,N+1) if(dp[i][x][y]) {
			ll t=dp[i][x][y];
			// loop
			(dp[i+1][y][y] += t*x)%=mo;
			// already
			(dp[i+1][x][y] += t*(y-x))%=mo;
			// new
			if(y<N) (dp[i+1][x][y+1] += t*(N-y))%=mo;
		}
	}
	
	cout<<dp[M][N][N]<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}

Submission Info

Submission Time
Task F - Road of the King
User kmjp
Language C++14 (GCC 5.4.1)
Score 1000
Code Size 1129 Byte
Status AC
Exec Time 397 ms
Memory 108032 KB

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 3 ms 256 KB
01-02.txt AC 3 ms 256 KB
01-03.txt AC 7 ms 2176 KB
01-04.txt AC 3 ms 256 KB
01-05.txt AC 18 ms 7808 KB
01-06.txt AC 135 ms 54912 KB
01-07.txt AC 389 ms 107136 KB
01-08.txt AC 395 ms 108032 KB
01-09.txt AC 396 ms 108032 KB
01-10.txt AC 397 ms 108032 KB
sample-01.txt AC 3 ms 256 KB
sample-02.txt AC 231 ms 81024 KB
sample-03.txt AC 3 ms 256 KB