CODE FESTIVAL 2016 Final

Submission #5396246

Source codeソースコード

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 1000005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
const int MOD = 1000000007;
int N,M;
int dp[305][305][305];
int inc(int a,int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
    return 1LL * a * b % MOD;
}
void update(int &x,int y) {
    x = inc(x,y);
}
void Solve() {
    read(N);read(M);
    dp[0][1][1] = 1;
    for(int i = 0 ; i < M ; ++i) {
	for(int j = 1 ; j <= i + 1 ; ++j) {
	    for(int k = 1 ; k <= i + 1 ; ++k) {
		if(!dp[i][j][k]) continue;
		update(dp[i + 1][j][k + 1],mul(dp[i][j][k],N - k));
		update(dp[i + 1][k][k],mul(dp[i][j][k],j));
		update(dp[i + 1][j][k],mul(dp[i][j][k],k - j));
	    }
	}
    }
    out(dp[M][N][N]);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}

Submission

Task問題 F - Road of the King
User nameユーザ名 sigongzi
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 1000
Source lengthソースコード長 1517 Byte
File nameファイル名
Exec time実行時間 64 ms
Memory usageメモリ使用量 108800 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 1 ms 256 KB
01-02.txt AC 1 ms 256 KB
01-03.txt AC 30 ms 108800 KB
01-04.txt AC 1 ms 256 KB
01-05.txt AC 30 ms 108800 KB
01-06.txt AC 38 ms 108800 KB
01-07.txt AC 64 ms 108800 KB
01-08.txt AC 64 ms 108800 KB
01-09.txt AC 64 ms 108800 KB
01-10.txt AC 64 ms 108800 KB
sample-01.txt AC 1 ms 256 KB
sample-02.txt AC 48 ms 108800 KB
sample-03.txt AC 17 ms 53504 KB