QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#709523#9561. 树数叔术cmk666100 ✓92ms11364kbC++2313.0kb2024-11-04 15:10:032024-11-04 15:10:05

Judging History

你现在查看的是最新测评结果

  • [2024-11-04 15:10:05]
  • 评测
  • 测评结果:100
  • 用时:92ms
  • 内存:11364kb
  • [2024-11-04 15:10:03]
  • 提交

answer

/*  _              _     _                                             _       __      __      __   
   / \     _   _  | |_  | |__     ___    _ __   _    ___   _ __ ___   | | __  / /_    / /_    / /_  
  / _ \   | | | | | __| | '_ \   / _ \  | '__| (_)  / __| | '_ ` _ \  | |/ / | '_ \  | '_ \  | '_ \ 
 / ___ \  | |_| | | |_  | | | | | (_) | | |     _  | (__  | | | | | | |   <  | (_) | | (_) | | (_) |
/_/   \_\  \__,_|  \__| |_| |_|  \___/  |_|    (_)  \___| |_| |_| |_| |_|\_\  \___/   \___/   \___/ 
[Created Time:       2024-11-04 14:41:45]
[Last Modified Time: 2024-11-04 15:09:58] */
#ifdef LOCAL
#include<bits/stdc++.h>
#include"debug.h"
#else
#pragma GCC optimize("Ofast", "unroll-loops")
#include<bits/stdc++.h>
#define D(...) ((void)0)
#endif
using namespace std; using ll = long long;
#define For(i, j, k) for ( int i = (j) ; i <= (k) ; i++ )
#define Fol(i, j, k) for ( int i = (j) ; i >= (k) ; i-- )
namespace FastIO
{
#define USE_FastIO
// ------------------------------
// #define DISABLE_MMAP
// ------------------------------
#if ( defined(LOCAL) || defined(_WIN32) ) && !defined(DISABLE_MMAP)
#define DISABLE_MMAP
#endif
#ifdef LOCAL
	inline void _chk_i() {}
	inline char _gc_nochk() { return getchar(); }
	inline char _gc() { return getchar(); }
	inline void _chk_o() {}
	inline void _pc_nochk(char c) { putchar(c); }
	inline void _pc(char c) { putchar(c); }
	template < int n > inline void _pnc_nochk(const char *c) { for ( int i = 0 ; i < n ; i++ ) putchar(c[i]); }
#else
#ifdef DISABLE_MMAP
	inline constexpr int _READ_SIZE = 1 << 18; inline static char _read_buffer[_READ_SIZE + 40], *_read_ptr = nullptr, *_read_ptr_end = nullptr; static inline bool _eof = false;
	inline void _chk_i() { if ( __builtin_expect(!_eof, true) && __builtin_expect(_read_ptr_end - _read_ptr < 40, false) ) { int sz = _read_ptr_end - _read_ptr; if ( sz ) memcpy(_read_buffer, _read_ptr, sz); char *beg = _read_buffer + sz; _read_ptr = _read_buffer, _read_ptr_end = beg + fread(beg, 1, _READ_SIZE, stdin); if ( __builtin_expect(_read_ptr_end != beg + _READ_SIZE, false) ) _eof = true, *_read_ptr_end = EOF; } }
	inline char _gc_nochk() { return __builtin_expect(_eof && _read_ptr == _read_ptr_end, false) ? EOF : *_read_ptr++; }
	inline char _gc() { _chk_i(); return _gc_nochk(); }
#else
#include<sys/mman.h>
#include<sys/stat.h>
	inline static char *_read_ptr = (char *)mmap(nullptr, [] { struct stat s; return fstat(0, &s), s.st_size; } (), 1, 2, 0, 0);
	inline void _chk_i() {}
	inline char _gc_nochk() { return *_read_ptr++; }
	inline char _gc() { return *_read_ptr++; }
#endif
	inline constexpr int _WRITE_SIZE = 1 << 18; inline static char _write_buffer[_WRITE_SIZE + 40], *_write_ptr = _write_buffer;
	inline void _chk_o() { if ( __builtin_expect(_write_ptr - _write_buffer > _WRITE_SIZE, false) ) fwrite(_write_buffer, 1, _write_ptr - _write_buffer, stdout), _write_ptr = _write_buffer; }
	inline void _pc_nochk(char c) { *_write_ptr++ = c; }
	inline void _pc(char c) { *_write_ptr++ = c, _chk_o(); }
	template < int n > inline void _pnc_nochk(const char *c) { memcpy(_write_ptr, c, n), _write_ptr += n; }
	inline struct _auto_flush { inline ~_auto_flush() { fwrite(_write_buffer, 1, _write_ptr - _write_buffer, stdout); } } _auto_flush;
#endif
#define println println_ // don't use C++23 std::println
	template < class T > inline constexpr bool _is_signed = numeric_limits < T >::is_signed;
	template < class T > inline constexpr bool _is_unsigned = numeric_limits < T >::is_integer && !_is_signed < T >;
#if __SIZEOF_LONG__ == 64
	template <> inline constexpr bool _is_signed < __int128 > = true;
	template <> inline constexpr bool _is_unsigned < __uint128_t > = true;
#endif
	inline bool _isgraph(char c) { return c >= 33; }
	inline bool _isdigit(char c) { return 48 <= c && c <= 57; } // or faster, remove c <= 57
	constexpr struct _table {
#ifndef LOCAL
	int i[65536];
#endif
	char o[40000]; constexpr _table() :
#ifndef LOCAL
	i{},
#endif
	o{} {
#ifndef LOCAL
	for ( int x = 0 ; x < 65536 ; x++ ) i[x] = -1; for ( int x = 0 ; x <= 9 ; x++ ) for ( int y = 0 ; y <= 9 ; y++ ) i[x + y * 256 + 12336] = x * 10 + y;
#endif
	for ( int x = 0 ; x < 10000 ; x++ ) for ( int y = 3, z = x ; ~y ; y-- ) o[x * 4 + y] = z % 10 + 48, z /= 10; } } _table;
	template < class T, int digit > inline constexpr T _pw10 = 10 * _pw10 < T, digit - 1 >;
	template < class T > inline constexpr T _pw10 < T, 0 > = 1;
	inline void read(char &c) { do c = _gc(); while ( !_isgraph(c) ); }
	inline void read_cstr(char *s) { char c = _gc(); while ( !_isgraph(c) ) c = _gc(); while ( _isgraph(c) ) *s++ = c, c = _gc(); *s = 0; }
	inline void read(string &s) { char c = _gc(); s.clear(); while ( !_isgraph(c) ) c = _gc(); while ( _isgraph(c) ) s.push_back(c), c = _gc(); }
	template < class T, bool neg >
#ifndef LOCAL
	__attribute__((no_sanitize("undefined")))
#endif
	inline void _read_int_suf(T &x) { _chk_i(); char c; while
#ifndef LOCAL
	( ~_table.i[*reinterpret_cast < unsigned short *& >(_read_ptr)] ) if constexpr ( neg ) x = x * 100 - _table.i[*reinterpret_cast < unsigned short *& >(_read_ptr)++]; else x = x * 100 + _table.i[*reinterpret_cast < unsigned short *& >(_read_ptr)++]; if
#endif
	( _isdigit(c = _gc_nochk()) ) if constexpr ( neg ) x = x * 10 - ( c & 15 ); else x = x * 10 + ( c & 15 ); }
	template < class T, enable_if_t < _is_signed < T >, int > = 0 > inline void read(T &x) { char c; while ( !_isdigit(c = _gc()) ) if ( c == 45 ) { _read_int_suf < T, true >(x = -( _gc_nochk() & 15 )); return; } _read_int_suf < T, false >(x = c & 15); }
	template < class T, enable_if_t < _is_unsigned < T >, int > = 0 > inline void read(T &x) { char c; while ( !_isdigit(c = _gc()) ); _read_int_suf < T, false >(x = c & 15); }
	inline void write(bool x) { _pc(x | 48); }
	inline void write(char c) { _pc(c); }
	inline void write_cstr(const char *s) { while ( *s ) _pc(*s++); }
	inline void write(const string &s) { for ( char c : s ) _pc(c); }
	template < class T, bool neg, int digit > inline void _write_int_suf(T x) { if constexpr ( digit == 4 ) _pnc_nochk < 4 >(_table.o + ( neg ? -x : x ) * 4); else _write_int_suf < T, neg, digit / 2 >(x / _pw10 < T, digit / 2 >), _write_int_suf < T, neg, digit / 2 >(x % _pw10 < T, digit / 2 >); }
	template < class T, bool neg, int digit > inline void _write_int_pre(T x) { if constexpr ( digit <= 4 ) if ( digit >= 3 && ( neg ? x <= -100 : x >= 100 ) ) if ( digit >= 4 && ( neg ? x <= -1000 : x >= 1000 ) ) _pnc_nochk < 4 >(_table.o + ( neg ? -x : x ) * 4); else _pnc_nochk < 3 >(_table.o + ( neg ? -x : x ) * 4 + 1); else if ( digit >= 2 && ( neg ? x <= -10 : x >= 10 ) ) _pnc_nochk < 2 >(_table.o + ( neg ? -x : x ) * 4 + 2); else _pc_nochk(( neg ? -x : x ) | 48); else { constexpr int cur = 1 << __lg(digit - 1); if ( neg ? x <= -_pw10 < T, cur > : x >= _pw10 < T, cur > ) _write_int_pre < T, neg, digit - cur >(x / _pw10 < T, cur >), _write_int_suf < T, neg, cur >(x % _pw10 < T, cur >); else _write_int_pre < T, neg, cur >(x); } }
	template < class T, enable_if_t < _is_signed < T >, int > = 0 > inline void write(T x) { if ( x >= 0 ) _write_int_pre < T, false, numeric_limits < T >::digits10 + 1 >(x); else _pc_nochk(45), _write_int_pre < T, true, numeric_limits < T >::digits10 + 1 >(x); _chk_o(); }
	template < class T, enable_if_t < _is_unsigned < T >, int > = 0 > inline void write(T x) { _write_int_pre < T, false, numeric_limits < T >::digits10 + 1 >(x), _chk_o(); }
	template < size_t N, class ...T > inline void _read_tuple(tuple < T... > &x) { read(get < N >(x)); if constexpr ( N + 1 != sizeof...(T) ) _read_tuple < N + 1, T... >(x); }
	template < size_t N, class ...T > inline void _write_tuple(const tuple < T... > &x) { write(get < N >(x)); if constexpr ( N + 1 != sizeof...(T) ) _pc(32), _write_tuple < N + 1, T... >(x); }
	template < class ...T > inline void read(tuple < T... > &x) { _read_tuple < 0, T... >(x); }
	template < class ...T > inline void write(const tuple < T... > &x) { _write_tuple < 0, T... >(x); }
	template < class T1, class T2 > inline void read(pair < T1, T2 > &x) { read(x.first), read(x.second); }
	template < class T1, class T2 > inline void write(const pair < T1, T2 > &x) { write(x.first), _pc(32), write(x.second); }
	template < class T > inline auto read(T &x) -> decltype(x.read(), void()) { x.read(); }
	template < class T > inline auto write(const T &x) -> decltype(x.write(), void()) { x.write(); }
	template < class T1, class ...T2 > inline void read(T1 &x, T2 &...y) { read(x), read(y...); }
	template < class ...T > inline void read_cstr(char *x, T *...y) { read_cstr(x), read_cstr(y...); }
	template < class T1, class ...T2 > inline void write(const T1 &x, const T2 &...y) { write(x), write(y...); }
	template < class ...T > inline void write_cstr(const char *x, const T *...y) { write_cstr(x), write_cstr(y...); }
	template < class T > inline void print(const T &x) { write(x); }
	inline void print_cstr(const char *x) { write_cstr(x); }
	template < class T1, class ...T2 > inline void print(const T1 &x, const T2 &...y) { write(x), _pc(32), print(y...); }
	template < class ...T > inline void print_cstr(const char *x, const T *...y) { write_cstr(x), _pc(32), print_cstr(y...); }
	inline void println() { _pc(10); }
	inline void println_cstr() { _pc(10); }
	template < class ...T > inline void println(const T &...x) { print(x...), _pc(10); }
	template < class ...T > inline void println_cstr(const T *...x) { print_cstr(x...), _pc(10); }
}	using FastIO::read, FastIO::read_cstr, FastIO::write, FastIO::write_cstr, FastIO::println, FastIO::println_cstr;
// old template
class DymanicModint
{
	using MI = DymanicModint; static __uint128_t B;
	inline constexpr DymanicModint(int x, int) : v(x) {}
	inline constexpr static int add(int x) { return x < P ? x : x - P; }
	inline constexpr static int sub(int x) { return x >= 0 ? x : x + P; }
	template < class T, enable_if_t < numeric_limits < T >::is_integer, int > = 0 >
	inline constexpr static int r(T x) { return add(x - ( ( B * x ) >> 64 ) * P); }
public:
	static int P; int v;
	inline constexpr static void set_mod(int x) { B = ( (__uint128_t)1 << 64 ) / ( P = x ); }
	inline constexpr DymanicModint() : v(0) {}
	inline constexpr DymanicModint(const MI &x) : v(x.v) {}
	template < class T, enable_if_t < numeric_limits < T >::is_integer, int > = 0 >
	inline constexpr DymanicModint(T x) : v(r(x)) {}
	template < class T, enable_if_t < numeric_limits < T >::is_integer, int > = 0 >
	explicit inline constexpr operator T()const { return v; }
	inline constexpr bool operator==(const MI &x)const { return v == x.v; }
	inline constexpr bool operator!=(const MI &x)const { return v != x.v; }
	inline constexpr MI &operator=(const MI &x) { v = x.v; return *this; }
	inline constexpr MI &operator++() { v < P - 1 ? v++ : v = 0; return *this; }
	inline constexpr MI operator++(int) { MI x = *this; v < P - 1 ? v++ : v = 0; return x; }
	inline constexpr MI &operator--() { v ? v-- : v = P - 1; return *this; }
	inline constexpr MI operator--(int) { MI x = *this; v ? v-- : v = P - 1; return x; }
	inline constexpr MI operator-()const { return MI(v ? P - v : 0, 0); }
	inline constexpr friend MI operator+(const MI &x, const MI &y) { return MI(add(x.v + y.v), 0); }
	inline constexpr friend MI operator-(const MI &x, const MI &y) { return MI(sub(x.v - y.v), 0); }
	inline constexpr friend MI operator*(const MI &x, const MI &y) { return MI(r((ll)x.v * y.v), 0); }
	inline constexpr friend MI operator/(const MI &x, const MI &y) { return x * y.inv(); }
	inline constexpr MI &operator+=(const MI &x) { v = add(v + x.v); return *this; }
	inline constexpr MI &operator-=(const MI &x) { v = sub(v - x.v); return *this; }
	inline constexpr MI &operator*=(const MI &x) { v = r((ll)v * x.v); return *this; }
	inline constexpr MI &operator/=(const MI &x) { return *this *= x.inv(); }
	template < class T, enable_if_t < numeric_limits < T >::is_integer, int > = 0 >
	inline constexpr MI qpow(T y)const
	{ MI x(*this), z(1, 0); while ( y ) { if ( y & 1 ) z *= x; if ( y >>= 1 ) x *= x; } return z; }
	template < class T, enable_if_t < numeric_limits < T >::is_integer, int > = 0 >
	inline constexpr friend MI qpow(const MI &x, T y) { return x.qpow(y); }
	inline constexpr MI inv()const { assert(v); return qpow(P - 2); }
	inline constexpr friend MI inv(const MI &x) { return x.inv(); }
	inline friend istream &operator>>(istream &is, MI &x) { return is >> x.v; }
	inline friend ostream &operator<<(ostream &os, const MI &x) { return os << x.v; }
};	int DymanicModint::P = 2; __uint128_t DymanicModint::B = 1ull << 63; using MI = DymanicModint;
int n, v, p; MI c[159][159], dp[159][159][159], o;
int main()
{
	read(n, v, p), MI::set_mod(p);
	if ( v >= n ) return println(0), 0;
	For(i, 0, n) { c[i][0] = 1; For(j, 1, n) c[i][j] = c[i - 1][j - 1] + c[i - 1][j]; }
	dp[0][1][0] = 1;
	For(i, 1, v) For(j, 0, n) For(k, 0, j) if ( dp[i - 1][j][k] )
	{
		For(l, 0, k - 1) dp[i][j][l] += dp[i - 1][j][k] * c[k][l];
		o = dp[i - 1][j][k] * j;
		For(l, 1, n - j) dp[i][j + l][k + l - 1] += o;
	}
	o = dp[v][n][0];
	For(i, 1, n) o *= i;
	return println(o.v), 0;
}
// 想上GM捏 想上GM捏 想上GM捏 想上GM捏 想上GM捏
// 伊娜可爱捏 伊娜贴贴捏

詳細信息

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 0ms
memory: 3584kb

input:

1 1 624295285

output:

0

result:

ok single line: '0'

Test #2:

score: 5
Accepted
time: 0ms
memory: 3728kb

input:

4 684813415 564954712

output:

0

result:

ok single line: '0'

Test #3:

score: 5
Accepted
time: 0ms
memory: 5740kb

input:

4 2 844826878

output:

24

result:

ok single line: '24'

Test #4:

score: 5
Accepted
time: 0ms
memory: 3928kb

input:

4 17724073 252218682

output:

0

result:

ok single line: '0'

Test #5:

score: 5
Accepted
time: 0ms
memory: 3716kb

input:

4 3 697681963

output:

384

result:

ok single line: '384'

Subtask #2:

score: 15
Accepted

Test #6:

score: 15
Accepted
time: 0ms
memory: 3700kb

input:

6 4 956647977

output:

238320

result:

ok single line: '238320'

Test #7:

score: 15
Accepted
time: 0ms
memory: 3560kb

input:

6 450615260 491361886

output:

0

result:

ok single line: '0'

Test #8:

score: 15
Accepted
time: 0ms
memory: 3912kb

input:

6 5 339344353

output:

933120

result:

ok single line: '933120'

Test #9:

score: 15
Accepted
time: 0ms
memory: 3972kb

input:

6 3 842228619

output:

23760

result:

ok single line: '23760'

Test #10:

score: 15
Accepted
time: 0ms
memory: 4052kb

input:

6 5 331699652

output:

933120

result:

ok single line: '933120'

Subtask #3:

score: 30
Accepted

Test #11:

score: 30
Accepted
time: 1ms
memory: 4432kb

input:

48 26 424594716

output:

362283012

result:

ok single line: '362283012'

Test #12:

score: 30
Accepted
time: 0ms
memory: 3612kb

input:

49 1000000000 738885247

output:

0

result:

ok single line: '0'

Test #13:

score: 30
Accepted
time: 0ms
memory: 4568kb

input:

48 39 688951620

output:

598399200

result:

ok single line: '598399200'

Test #14:

score: 30
Accepted
time: 0ms
memory: 3696kb

input:

50 476039414 292870080

output:

0

result:

ok single line: '0'

Test #15:

score: 30
Accepted
time: 2ms
memory: 4548kb

input:

50 48 245196368

output:

123576912

result:

ok single line: '123576912'

Subtask #4:

score: 50
Accepted

Test #16:

score: 50
Accepted
time: 0ms
memory: 3624kb

input:

150 526250070 197316869

output:

0

result:

ok single line: '0'

Test #17:

score: 50
Accepted
time: 92ms
memory: 10756kb

input:

149 116 671784452

output:

18945228

result:

ok single line: '18945228'

Test #18:

score: 50
Accepted
time: 88ms
memory: 10988kb

input:

146 144 906402626

output:

438777234

result:

ok single line: '438777234'

Test #19:

score: 50
Accepted
time: 89ms
memory: 11280kb

input:

147 143 705666477

output:

70408701

result:

ok single line: '70408701'

Test #20:

score: 50
Accepted
time: 87ms
memory: 11364kb

input:

150 147 453481175

output:

336290325

result:

ok single line: '336290325'