結果

問題 No.1667 Forest
ユーザー kotatsugamekotatsugame
提出日時 2021-09-03 22:25:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 703 bytes
コンパイル時間 525 ms
コンパイル使用メモリ 65,972 KB
実行使用メモリ 4,568 KB
最終ジャッジ日時 2023-08-21 22:41:56
合計ジャッジ時間 3,373 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 AC 11 ms
4,376 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 99 ms
4,380 KB
testcase_09 AC 59 ms
4,380 KB
testcase_10 AC 29 ms
4,380 KB
testcase_11 AC 5 ms
4,384 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:10:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   10 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
using namespace std;
int N,mod;
long modpow(long a,long b){return b?modpow(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
long T[301];
long dp[301][301];
long fac[301],invfac[301];
long ans[301];
long comb(int a,int b){return fac[a]*invfac[b]%mod*invfac[a-b]%mod;}
main()
{
	cin>>N>>mod;
	fac[0]=1;
	for(int i=1;i<=N;i++)fac[i]=fac[i-1]*i%mod;
	invfac[N]=modpow(fac[N],mod-2);
	for(int i=N;i--;)invfac[i]=invfac[i+1]*(i+1)%mod;
	T[1]=1;
	for(int k=2;k<=N;k++)T[k]=modpow(k,k-2);
	dp[0][0]=1;
	for(int c=0;c<N;c++)
	{
		for(int i=0;i<=N;i++)
		{
			for(int k=1;i+k<=N;k++)
			{
				(dp[c+k-1][i+k]+=dp[c][i]*comb(N-i-1,k-1)%mod*T[k]%mod)%=mod;
			}
		}
	}
	for(int i=0;i<N;i++)cout<<dp[i][N]<<endl;
}
0