CODE FESTIVAL 2016 Final

Submission #6775383

Source codeソースコード

#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

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

Compiler messageコンパイルメッセージ

./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);
^

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 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