QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#548304#7063. Space Stationcmk666TL 615ms95220kbC++2310.5kb2024-09-05 16:58:162024-09-05 16:58:19

Judging History

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

  • [2024-09-05 16:58:19]
  • 评测
  • 测评结果:TL
  • 用时:615ms
  • 内存:95220kb
  • [2024-09-05 16:58:16]
  • 提交

answer

/*  _              _     _                                             _       __      __      __   
   / \     _   _  | |_  | |__     ___    _ __   _    ___   _ __ ___   | | __  / /_    / /_    / /_  
  / _ \   | | | | | __| | '_ \   / _ \  | '__| (_)  / __| | '_ ` _ \  | |/ / | '_ \  | '_ \  | '_ \ 
 / ___ \  | |_| | | |_  | | | | | (_) | | |     _  | (__  | | | | | | |   <  | (_) | | (_) | | (_) |
/_/   \_\  \__,_|  \__| |_| |_|  \___/  |_|    (_)  \___| |_| |_| |_| |_|\_\  \___/   \___/   \___/ 
[Created Time:       2024-09-05 16:42:07]
[Last Modified Time: 2024-09-05 16:58:01] */
#pragma GCC optimize("Ofast", "unroll-loops")
#include<bits/stdc++.h>
#ifdef LOCAL
#include"debug.h"
#else
#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 DISABLE_MMAP
// ------------------------------
#if ( defined(LOCAL) || defined(_WIN32) ) && !defined(DISABLE_MMAP)
#define DISABLE_MMAP
#endif
#ifdef LOCAL
	inline char gc() { return getchar(); }
	inline void pc(char c) { putchar(c); }
#else
#ifdef DISABLE_MMAP
	inline constexpr int _READ_SIZE = 1 << 18;
	inline static char _read_buffer[_READ_SIZE], *_read_ptr = nullptr, *_read_ptr_end = nullptr;
	inline char gc()
	{
		if ( __builtin_expect(_read_ptr == _read_ptr_end, false) )
		{
			_read_ptr = _read_buffer, _read_ptr_end = _read_buffer + fread(_read_buffer, 1, _READ_SIZE, stdin);
			if ( __builtin_expect(_read_ptr == _read_ptr_end, false) ) return EOF;
		}
		return *_read_ptr++;
	}
#else
#include<sys/mman.h>
	inline static const char *_read_ptr = (const char *)mmap(nullptr, 0x7fffffff, 1, 2, 0, 0);
	inline char gc() { return *_read_ptr++; }
#endif
	inline constexpr int _WRITE_SIZE = 1 << 18;
	inline static char _write_buffer[_WRITE_SIZE], *_write_ptr = _write_buffer;
	inline void pc(char c)
	{
		*_write_ptr++ = c;
		if ( __builtin_expect(_write_buffer + _WRITE_SIZE == _write_ptr, false) )
			fwrite(_write_buffer, 1, _write_ptr - _write_buffer, stdout), _write_ptr = _write_buffer;
	}
	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 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, enable_if_t < _is_signed < T >, int > = 0 >
	inline void read(T &x)
	{
		char c = gc(); bool f = true; x = 0;
		while ( !isdigit(c) ) { if ( c == 45 ) f = false; c = gc(); }
		if ( f ) while ( isdigit(c) ) x = x * 10 + ( c & 15 ), c = gc();
		else     while ( isdigit(c) ) x = x * 10 - ( c & 15 ), c = gc();
	}
	template < class T, enable_if_t < _is_unsigned < T >, int > = 0 >
	inline void read(T &x)
	{
		char c = gc(); while ( !isdigit(c) ) c = gc();
		x = 0; while ( isdigit(c) ) x = x * 10 + ( c & 15 ), c = gc();
	}
	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, enable_if_t < _is_signed < T >, int > = 0 >
	inline void write(T x)
	{
		char buffer[numeric_limits < T >::digits10 + 1]; int digits = 0;
		if ( x >= 0 )  do buffer[digits++] =  ( x % 10 ) | 48, x /= 10; while ( x );
		else { pc(45); do buffer[digits++] = -( x % 10 ) | 48, x /= 10; while ( x ); }
		while ( digits ) pc(buffer[--digits]);
	}
	template < class T, enable_if_t < _is_unsigned < T >, int > = 0 >
	inline void write(T x)
	{
		char buffer[numeric_limits < T >::digits10]; int digits = 0;
		do buffer[digits++] = ( x % 10 ) | 48, x /= 10; while ( x );
		while ( digits ) pc(buffer[--digits]);
	}
	template < int N > struct _tuple_io_helper
	{
		template < class ...T > static inline void _read(tuple < T... > &x) { _tuple_io_helper < N - 1 >::_read(x), read(get<N - 1>(x)); }
		template < class ...T > static inline void _write(const tuple < T... > &x) { _tuple_io_helper < N - 1 >::_write(x), pc(32), write(get<N - 1>(x)); }
	};
	template <> struct _tuple_io_helper < 1 >
	{
		template < class ...T > static inline void _read(tuple < T... > &x) { read(get<0>(x)); }
		template < class ...T > static inline void _write(const tuple < T... > &x) { write(get<0>(x)); }
	};
	template < class ...T > inline void read(tuple < T... > &x) { _tuple_io_helper < sizeof...(T) >::_read(x); }
	template < class ...T > inline void write(const tuple < T... > &x) { _tuple_io_helper < sizeof...(T) >::_write(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 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;
template < int P_ > class Modint
{
	using MI = Modint;
	inline Modint(int x, int) : v(x) {}
	inline static int add(int x) { return x < P ? x : x - P; }
	inline static int sub(int x) { return x >= 0 ? x : x + P; }
public:
	static constexpr int P = P_; int v;
	inline Modint() : v(0) {}
	inline Modint(const MI &x) : v(x.v) {}
	template < class T, enable_if_t < numeric_limits < T >::is_integer, int > = 0 >
	inline Modint(T x) : v(sub(x % P)) {}
	template < class T, enable_if_t < numeric_limits < T >::is_integer, int > = 0 >
	explicit inline operator T()const { return v; }
	inline friend bool operator==(const MI &x, const MI &y) { return x.v == y.v; }
	inline friend bool operator!=(const MI &x, const MI &y) { return x.v != y.v; }
	inline MI &operator=(const MI &x) & { v = x.v; return *this; }
	inline MI &operator++() & { v < P - 1 ? v++ : v = 0; return *this; }
	inline MI operator++(int) & { MI x = *this; v < P - 1 ? v++ : v = 0; return x; }
	inline MI &operator--() & { v ? v-- : v = P - 1; return *this; }
	inline MI operator--(int) & { MI x = *this; v ? v-- : v = P - 1; return x; }
	inline MI operator-()const { return MI(v ? P - v : 0, 0); }
	inline friend MI operator+(const MI &x, const MI &y) { return MI(add(x.v + y.v), 0); }
	inline friend MI operator-(const MI &x, const MI &y) { return MI(sub(x.v - y.v), 0); }
	inline friend MI operator*(const MI &x, const MI &y) { return MI((ll)x.v * y.v % P, 0); }
	inline friend MI operator/(const MI &x, const MI &y) { return x * y.inv(); }
	inline MI &operator+=(const MI &x) & { v = add(v + x.v); return *this; }
	inline MI &operator-=(const MI &x) & { v = sub(v - x.v); return *this; }
	inline MI &operator*=(const MI &x) & { v = (ll)v * x.v % P; return *this; }
	inline MI &operator/=(const MI &x) & { return *this *= x.inv(); }
	template < class T, enable_if_t < numeric_limits < T >::is_integer, int > = 0 >
	inline 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 friend MI qpow(const MI &x, T y) { return x.qpow(y); }
	inline MI inv()const { assert(v); return qpow(P - 2); }
	inline 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; }
};	using MI = Modint < 1000000007 >;
struct binom
{
	MI fac[100009], ifac[100009];
	inline binom()
	{
		constexpr int n = sizeof(fac) / sizeof(*fac) - 1;
		fac[0] = 1; For(i, 1, n) fac[i] = i * fac[i - 1];
		ifac[n] = inv(fac[n]); Fol(i, n, 1) ifac[i - 1] = i * ifac[i];
	}
}	binom;
inline MI fac(int x) { return x >= 0 ? binom.fac[x] : 0; }
inline MI ifac(int x) { return x >= 0 ? binom.ifac[x] : 0; }
inline MI c(int x, int y) { return x >= y && y >= 0 ? fac(x) * ifac(y) * ifac(x - y) : 0; }
mt19937 rnd(chrono::system_clock::now().time_since_epoch().count());
template < class T > inline T R(T l, T r) { return uniform_int_distribution < T >(l, r)(rnd); }
using ull = unsigned long long; using A = array < int, 51 >; const ull B = R(233333ull, -233333ull);
struct H { inline ull operator()(const A &x)const { ull z = 0; For(i, 1, 50) z = z * B + x[i]; return z; } };
int n, a[100009]; A cnt; unordered_map < A, MI, H > mem; MI ans;
inline MI dfs(int s, const A &c)
{
	int mx = 0; Fol(i, 50, 1) if ( c[i] ) { mx = i; break; }
	if ( s >= mx ) { int cc = 0; For(i, 1, mx) cc += c[i]; return fac(cc); }
	if ( mem.count(c) ) return mem[c];
	MI z = 0; For(i, 1, s) if ( c[i] ) { A cc = c; cc[i]--, z += c[i] * dfs(s + i, cc); } return mem[c] = z;
}
int main()
{
	read(n);
	For(i, 0, n) read(a[i]);
	For(i, 1, n) cnt[a[i]]++;
	ans = dfs(*a, cnt);
	For(i, 1, cnt[0]) ans *= n - cnt[0] + i;
	return println(ans.v), 0;
}
// 想上GM捏 想上GM捏 想上GM捏 想上GM捏 想上GM捏
// 伊娜可爱捏 伊娜贴贴捏

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 4488kb

input:

3
2 1 2 3

output:

4

result:

ok single line: '4'

Test #2:

score: 0
Accepted
time: 0ms
memory: 4648kb

input:

5
1 1 1 1 2 3

output:

54

result:

ok single line: '54'

Test #3:

score: 0
Accepted
time: 0ms
memory: 5132kb

input:

100000
47 25 43 22 17 6 15 17 45 4 14 34 46 22 0 8 2 48 41 6 49 42 21 25 48 43 2 17 27 25 38 31 39 48 13 49 24 30 36 19 29 47 48 1 4 5 12 9 21 39 30 21 8 4 9 45 18 0 3 29 26 18 24 39 31 49 22 4 46 21 27 11 11 7 8 3 26 25 29 4 1 21 34 4 44 39 13 26 33 44 5 17 10 32 37 25 44 34 17 14 40 32 27 39 41 6 ...

output:

268605493

result:

ok single line: '268605493'

Test #4:

score: 0
Accepted
time: 0ms
memory: 5168kb

input:

100000
35 39 20 34 18 5 21 21 45 38 48 44 50 42 35 23 21 18 24 9 40 18 16 20 41 27 25 4 0 5 9 7 39 26 47 13 18 27 43 45 31 20 45 39 7 29 4 41 6 39 4 27 7 24 42 10 49 21 9 21 33 12 7 2 24 13 47 11 43 25 8 18 5 14 44 9 14 50 50 19 6 18 45 41 0 27 20 44 17 19 5 26 38 19 1 30 10 32 46 4 24 27 28 32 27 3...

output:

590621358

result:

ok single line: '590621358'

Test #5:

score: 0
Accepted
time: 25ms
memory: 9640kb

input:

100000
21 4 24 20 20 30 50 25 47 22 31 30 2 37 43 13 16 12 8 39 31 18 10 42 32 10 49 17 46 35 5 36 13 4 32 4 12 22 49 44 6 18 40 24 34 4 48 22 15 10 1 31 30 44 49 24 29 16 39 11 13 31 42 39 17 28 20 18 15 30 40 23 49 45 3 15 2 24 21 34 11 15 5 2 7 17 27 11 2 44 31 38 16 32 17 9 2 30 49 18 35 46 30 5...

output:

983292446

result:

ok single line: '983292446'

Test #6:

score: 0
Accepted
time: 490ms
memory: 78416kb

input:

100000
7 20 29 6 48 4 29 30 48 7 16 15 7 7 26 28 38 32 42 43 47 19 4 37 25 21 21 3 43 13 2 38 14 34 40 19 7 18 5 43 33 16 36 11 35 30 15 2 25 10 49 9 2 40 31 40 9 36 19 28 19 23 26 27 10 18 45 24 38 35 48 6 42 27 13 22 16 50 17 25 42 10 16 15 41 30 6 31 36 17 31 49 18 18 33 14 19 5 27 7 19 15 32 43 ...

output:

363626098

result:

ok single line: '363626098'

Test #7:

score: 0
Accepted
time: 2ms
memory: 5068kb

input:

100000
46 11 7 43 50 4 34 33 49 42 49 0 11 1 34 42 33 26 26 22 39 46 24 33 18 5 44 16 15 42 23 14 14 11 23 10 27 15 11 18 35 39 6 48 12 4 8 34 34 34 48 14 0 9 11 3 41 6 25 19 50 17 9 12 27 33 44 31 36 14 29 12 9 9 23 27 4 0 39 39 46 32 27 29 48 19 13 48 20 41 32 34 47 5 23 17 37 4 29 48 4 35 34 10 3...

output:

545614387

result:

ok single line: '545614387'

Test #8:

score: 0
Accepted
time: 7ms
memory: 5336kb

input:

100000
33 26 12 4 27 29 13 37 50 26 33 35 14 21 17 6 4 22 9 50 30 47 19 28 10 40 16 30 11 21 20 17 12 40 6 24 22 35 18 16 10 38 2 34 40 4 0 14 43 32 45 18 22 3 44 18 46 27 5 9 4 35 44 50 20 50 17 38 8 17 11 18 2 14 7 33 46 25 10 3 1 28 12 41 4 8 21 17 30 15 32 44 25 44 38 48 29 2 6 11 14 4 35 2 42 4...

output:

93496998

result:

ok single line: '93496998'

Test #9:

score: 0
Accepted
time: 32ms
memory: 10520kb

input:

100000
20 41 41 40 28 3 16 41 1 11 41 47 19 16 0 21 23 41 43 3 46 47 13 48 28 48 40 16 33 0 16 44 38 18 41 15 16 32 24 17 12 35 49 20 42 28 44 46 28 5 43 48 22 25 26 9 25 48 35 27 35 28 27 37 13 15 42 46 5 22 17 25 46 47 18 40 34 0 5 44 30 23 23 3 37 23 2 35 14 15 32 4 2 30 2 2 46 2 35 2 49 0 37 21 ...

output:

558286380

result:

ok single line: '558286380'

Test #10:

score: 0
Accepted
time: 615ms
memory: 95220kb

input:

100000
6 6 45 27 30 1 47 45 1 45 25 31 50 37 8 10 19 36 28 33 37 23 8 45 21 33 12 29 30 29 36 47 38 47 50 4 10 27 31 42 38 8 44 31 19 3 37 27 37 4 14 2 44 19 7 23 6 17 40 18 41 46 12 50 6 4 41 26 28 27 50 31 39 29 27 45 22 25 27 9 36 21 34 14 45 11 9 2 50 39 32 15 4 17 17 30 12 0 38 16 35 19 39 13 3...

output:

294711323

result:

ok single line: '294711323'

Test #11:

score: 0
Accepted
time: 2ms
memory: 5304kb

input:

100000
45 22 24 14 7 26 0 48 1 30 9 17 2 32 43 25 40 5 11 11 29 23 28 40 13 17 36 43 2 33 32 23 37 24 33 21 5 23 36 40 40 6 14 17 47 28 29 7 47 27 13 6 16 40 39 38 37 38 21 7 22 40 47 36 24 19 15 33 0 32 31 38 32 10 37 0 36 50 49 50 41 42 46 27 27 26 15 21 34 12 32 25 31 5 32 35 5 50 16 5 46 39 15 3...

output:

523779527

result:

ok single line: '523779527'

Test #12:

score: 0
Accepted
time: 4ms
memory: 5260kb

input:

100000
35 17 27 31 8 22 13 24 9 5 26 31 40 34 8 29 11 19 8 33 49 15 45 38 32 21 11 3 14 29 6 13 5 31 39 42 26 49 37 43 7 17 1 11 26 5 27 23 23 4 34 31 39 14 48 7 30 19 45 3 5 4 0 15 50 23 20 11 11 2 43 33 39 19 45 10 2 34 48 1 19 12 14 42 15 39 1 8 44 45 9 13 29 26 22 4 17 43 32 29 14 31 8 0 40 5 5 ...

output:

845953523

result:

ok single line: '845953523'

Test #13:

score: 0
Accepted
time: 0ms
memory: 5104kb

input:

100000
8 3 1 5 0 0 3 1 5 10 39 44 42 39 38 40 42 47 47 37 42 43 43 42 50 38 41 44 45 43 38 49 45 39 46 40 38 50 48 40 50 45 44 38 42 45 41 44 50 46 39 37 37 43 42 50 46 40 45 38 50 47 42 46 50 41 38 46 44 38 46 38 47 47 38 40 42 50 49 41 42 45 48 49 38 50 40 44 45 43 44 40 46 50 40 50 50 44 43 41 44...

output:

0

result:

ok single line: '0'

Test #14:

score: 0
Accepted
time: 2ms
memory: 5104kb

input:

100000
10 4 0 5 4 0 8 8 1 1 43 46 46 47 50 48 49 49 43 49 42 42 47 50 48 43 42 45 42 44 48 43 47 47 49 43 48 44 42 47 46 43 49 49 49 44 44 48 46 46 48 45 49 48 50 45 50 43 50 50 50 43 45 48 42 46 47 42 49 48 48 43 50 43 50 47 49 42 50 49 48 48 43 50 47 48 49 42 42 45 46 49 45 45 47 44 44 45 47 45 50...

output:

0

result:

ok single line: '0'

Test #15:

score: 0
Accepted
time: 2ms
memory: 5024kb

input:

100000
1 10 9 6 6 0 9 8 0 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 5...

output:

0

result:

ok single line: '0'

Test #16:

score: 0
Accepted
time: 2ms
memory: 5168kb

input:

100000
10 7 7 0 3 7 0 8 0 5 48 48 49 49 50 48 48 50 48 49 50 49 49 48 48 48 49 48 48 48 50 49 48 48 48 48 50 49 49 49 48 50 49 48 49 49 50 50 49 50 50 48 50 49 48 50 49 48 50 48 50 48 49 49 48 49 49 50 50 48 48 50 50 48 50 49 48 50 49 50 49 48 48 50 49 48 49 49 50 49 50 48 48 49 49 48 49 50 50 49 48...

output:

0

result:

ok single line: '0'

Test #17:

score: 0
Accepted
time: 2ms
memory: 5124kb

input:

100000
5 9 5 0 8 7 9 45 45 46 49 45 47 46 45 45 47 46 46 44 46 47 49 48 47 48 45 46 49 45 44 47 44 45 48 45 45 46 50 48 46 48 45 47 50 50 46 48 47 50 47 44 44 44 46 44 48 49 50 44 47 49 49 50 45 49 49 45 45 48 47 46 47 44 49 50 50 48 50 50 50 45 50 48 45 48 50 50 49 47 50 47 49 49 47 49 45 45 47 50 ...

output:

0

result:

ok single line: '0'

Test #18:

score: -100
Time Limit Exceeded

input:

100000
1 25 50 6 21 4 25 36 20 32 10 14 44 0 19 1 38 41 5 25 38 11 20 11 37 5 4 19 39 11 45 16 38 14 44 20 38 25 32 5 34 37 28 4 41 4 12 34 31 32 11 18 33 10 6 16 29 40 24 14 9 17 16 42 26 16 24 4 46 34 20 24 27 21 27 17 17 7 8 50 0 36 30 4 5 16 43 0 19 29 25 11 16 0 50 30 12 50 26 9 0 46 38 11 50 4...

output:


result: