結果

問題 No.1667 Forest
ユーザー XDXD
提出日時 2021-11-18 16:22:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,212 ms / 3,000 ms
コード長 3,710 bytes
コンパイル時間 1,368 ms
コンパイル使用メモリ 166,660 KB
実行使用メモリ 5,936 KB
最終ジャッジ日時 2023-08-27 02:54:49
合計ジャッジ時間 16,416 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,212 ms
5,740 KB
testcase_01 AC 2,208 ms
5,744 KB
testcase_02 AC 2,190 ms
5,936 KB
testcase_03 AC 17 ms
5,728 KB
testcase_04 AC 2,141 ms
5,620 KB
testcase_05 AC 1,243 ms
5,684 KB
testcase_06 AC 743 ms
5,576 KB
testcase_07 AC 440 ms
5,532 KB
testcase_08 AC 209 ms
5,404 KB
testcase_09 AC 116 ms
5,428 KB
testcase_10 AC 55 ms
5,428 KB
testcase_11 AC 8 ms
5,480 KB
testcase_12 AC 2 ms
5,440 KB
testcase_13 AC 2 ms
5,296 KB
testcase_14 AC 2 ms
5,456 KB
testcase_15 AC 2 ms
5,464 KB
testcase_16 AC 2 ms
5,460 KB
testcase_17 AC 2 ms
5,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define forn(i,s,t) for(register int i=(s); i<=(t); ++i)
#define forl(i,s,t) for(register i64 i=(s); i<=(t); ++i)
#define form(i,s,t) for(register int i=(s); i>=(t); --i)
#define rep(i,s,t) for(register int i=(s); i<(t); ++i)
#define IT(u) for(register int i=G[u]; i; i=E[i].nxt)
using namespace std;
namespace FASTIO {
	const int SIZ = 1 << 26 | 1;
	char ibuf[SIZ], obuf[SIZ], *iS = ibuf, *iT = ibuf, *oS = obuf, *oT = obuf + SIZ - 1, qwq[60], qaq;
	#define gc() (iS == iT && (iT = (iS = ibuf) + fread(ibuf, 1, SIZ, stdin), iS == iT) ? EOF : *iS++)
	template<typename T>
	inline void Rdn(T& A) {
		register bool fl = 0;
		register char ch = gc(); A = 0;
		while(!isdigit(ch)) fl = (ch == '-'), ch = gc();
		while(isdigit(ch)) A = (A * 10) + (ch & 15), ch = gc();
		fl && (A = -A);
	}
	inline void Rdn(char& c) {while((c = gc()) == ' ' || c == '\n' || c == '\r');}
	inline void Rdn(char* s) {
		while((*s = gc()) == ' ' || *s == '\n' || *s == '\r') ;
		if(*s == EOF) return ;
		while(*s != ' ' && *s != '\n' && *s != '\r' && *s != EOF) *(++s) = gc();
		*s = 0;
	}
	template<typename T, typename ...U>
	inline void Rdn(T& A, U& ...B) {Rdn(A), Rdn(B...);}
	inline void flush() {fwrite(obuf, 1, oS - obuf, stdout), oS = obuf;}
	inline void pc(char c) {*oS ++ = c; if(oS == oT) flush();}
	template<typename T>
	inline void Wtn(T A) {
		if(!A) return pc('0'); if(A < 0) pc('-'), A = -A;
		while(A) qwq[++qaq] = A % 10 + '0', A /= 10;
		while(qaq) pc(qwq[qaq -- ]);
	}
	inline void Wtn(char A) {pc(A);}
	inline void Wtn(char *s) {while(*s) pc(*s), ++s;}
	inline void Wtn(const char *s) {while(*s) pc(*s), ++s;}
	template<typename T, typename ...U>
	inline void Wtn(T A, U ...B) {Wtn(A), Wtn(B...);}
#undef gc
}
using FASTIO :: Rdn;
using FASTIO :: Wtn;
using FASTIO :: flush;
int Mod;
namespace Modint {
	struct Mint {
		int res;
		Mint() {}
		Mint(int _r) : res(_r) {}
		inline friend Mint operator + (const Mint& A, const Mint& B) {
			return Mint((A.res + B.res >= Mod) ? (A.res + B.res - Mod) : (A.res + B.res));
		}
		inline friend Mint operator - (const Mint& A, const Mint& B) {return A + Mint(Mod - B.res); }
		inline friend Mint operator * (const Mint& A, const Mint& B) {return Mint(1ll * A.res * B.res % Mod); }
		inline friend Mint& operator += (Mint& A, const Mint& B) {return A = A + B; }
		inline friend Mint& operator -= (Mint& A, const Mint& B) {return A = A - B; }
		inline friend Mint& operator *= (Mint& A, const Mint& B) {return A = A * B; }
		inline friend Mint q_pow(Mint p, int k = Mod - 2) {
			Mint res(1);
			for (; k; k >>= 1, p *= p) (k & 1) && (res *= p, 0);
			return res;
		}
	} ;
}
using Modint :: Mint;
typedef long long i64;
typedef double f64;
typedef unsigned long long u64;
typedef pair<i64, i64> pii;
typedef pair<int, u64> piu;
const int N = 3e2 + 5;
const i64 INF = 1e18;
inline void init() {}
Mint fac[N], ifac[N];
inline void table(int lim) {
	fac[0] = Mint(1);
	forn (i, 1, lim) fac[i] = fac[i - 1] * Mint(i);
	ifac[lim] = q_pow(fac[lim]);
	form (i, lim - 1, 0) ifac[i] = ifac[i + 1] * Mint(i + 1);
}
inline Mint C(int n, int r) {
	if (n < 0 || r < 0 || n < r) return Mint(0);
	return fac[n] * ifac[r] * ifac[n - r];
}
inline Mint F(int n) {
	if (n == 1) return Mint(1);
	else return q_pow(Mint(n), n - 2);
}
int n; Mint f[N][N];
inline void solve() {
	Rdn(n, Mod), table(n);
	f[0][0] = Mint(1);
	forn (i, 1, n) forn (j, 1, n) {
//		f[i][j] += f[i - 1][j - 1];
		forn (k, 1, j) f[i][j] += f[i - 1][j - k] * C(n - (j - k), k) * F(k);
	}
//	forn (i, 1, n) forn (j, 1, n) Wtn(f[i][j].res, " \n"[j == n]);
	form (i, n, 1) Wtn((f[i][n] * q_pow(fac[i])).res, '\n');
}
int Trd;
int main() {
	Trd = 1;
	while(Trd--) init(), solve(); flush();
	return 0;
}
0