CODE FESTIVAL 2016 Final

Submission #1914374

Source codeソースコード

#include <iostream>
using namespace std;
const int mod = 1000000007;
int N, M, dp[309][309][309]; bool vis[309][309][309];
int solve(int t, int terr, int half) {
	if (t == M) return (terr == N ? 1 : 0);
	if (vis[t][terr][half]) return dp[t][terr][half];
	int ret = 0;
	if (half == 0) {
		ret = (ret + 1LL * solve(t + 1, terr, half) * terr) % mod;
		if(terr < N) ret = (ret + solve(t + 1, terr, half + 1)) % mod;
	}
	else {
		ret = (ret + 1LL * solve(t + 1, terr, half) * half) % mod;
		ret = (ret + 1LL * solve(t + 1, terr + half, 0) * terr) % mod;
		if(terr + half < N) ret = (ret + 1LL * solve(t + 1, terr, half + 1)) % mod;
	}
	vis[t][terr][half] = true;
	dp[t][terr][half] = ret;
	return ret;
}
int main() {
	cin >> N >> M;
	int ret = solve(0, 1, 0);
	for (int i = 1; i < N; i++) ret = 1LL * ret * i % mod;
	cout << ret << endl;
	return 0;
}

Submission

Task問題 F - Road of the King
User nameユーザ名 square1001
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 1000
Source lengthソースコード長 872 Byte
File nameファイル名
Exec time実行時間 157 ms
Memory usageメモリ使用量 139648 KB

Test case

Set

Set name Score得点 / Max score Cases
sample - sample-01.txt,sample-02.txt,sample-03.txt
all 1000 / 1000 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

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
01-01.txt AC 2 ms 2304 KB
01-02.txt AC 2 ms 2304 KB
01-03.txt AC 28 ms 139648 KB
01-04.txt AC 2 ms 2304 KB
01-05.txt AC 28 ms 139648 KB
01-06.txt AC 54 ms 139648 KB
01-07.txt AC 156 ms 139648 KB
01-08.txt AC 157 ms 139648 KB
01-09.txt AC 157 ms 139648 KB
01-10.txt AC 157 ms 139648 KB
sample-01.txt AC 2 ms 2304 KB
sample-02.txt AC 92 ms 139648 KB
sample-03.txt AC 30 ms 70016 KB