CODE FESTIVAL 2016 Final

Submission #1891544

Source codeソースコード

#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[310][310][310];

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

Task問題 F - Road of the King
User nameユーザ名 seica
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 1000
Source lengthソースコード長 1667 Byte
File nameファイル名
Exec time実行時間 179 ms
Memory usageメモリ使用量 226816 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 84 ms 223488 KB
01-04.txt AC 2 ms 1024 KB
01-05.txt AC 45 ms 223488 KB
01-06.txt AC 58 ms 225920 KB
01-07.txt AC 170 ms 224768 KB
01-08.txt AC 177 ms 226816 KB
01-09.txt AC 178 ms 226816 KB
01-10.txt AC 179 ms 226816 KB
sample-01.txt AC 2 ms 2304 KB
sample-02.txt AC 80 ms 226304 KB
sample-03.txt AC 91 ms 114176 KB