QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#271676 | #7875. Queue Sorting | ucup-team896# | WA | 91ms | 4424kb | C++23 | 10.3kb | 2023-12-02 14:00:53 | 2023-12-02 14:00:54 |
Judging History
answer
/*
* @Author: cmk666
* @Created time: 2023-12-02 13:46:39
* @Last Modified time: 2023-12-02 14:00:27
*/
#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 IN_HAS_NEG
// #define OUT_HAS_NEG
// #define CHK_EOF
// #define DISABLE_MMAP
// ------------------------------
#if __cplusplus < 201400
#error Please use C++14 or higher.
#endif
#if __cplusplus > 201700
#define INLINE_V inline
#else
#define INLINE_V
#endif
#if ( defined(LOCAL) || defined(_WIN32) ) && !defined(DISABLE_MMAP)
#define DISABLE_MMAP
#endif
#ifndef DISABLE_MMAP
#include<sys/mman.h>
#endif
#ifdef LOCAL
inline char gc() { return getchar(); }
inline void pc(char c) { putchar(c); }
#else
#ifdef DISABLE_MMAP
INLINE_V constexpr int _READ_SIZE = 1 << 18;
INLINE_V 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);
#ifdef CHK_EOF
if ( __builtin_expect(_read_ptr == _read_ptr_end, false) ) return EOF;
#endif
}
return *_read_ptr++;
}
#else
INLINE_V static const char *_read_ptr = (const char *)mmap(nullptr, INT_MAX, 1, 2, 0, 0);
inline char gc() { return *_read_ptr++; }
#endif
INLINE_V constexpr int _WRITE_SIZE = 1 << 18;
INLINE_V 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_V struct _auto_flush
{
inline ~_auto_flush() { fwrite(_write_buffer, 1, _write_ptr - _write_buffer, stdout); }
} _auto_flush;
#endif
#ifdef CHK_EOF
inline constexpr bool _isdigit(char c) { return ( c & 16 ) && c != EOF; }
inline constexpr bool _isgraph(char c) { return c > 32 && c != EOF; }
#else
inline constexpr bool _isdigit(char c) { return c & 16; }
inline constexpr bool _isgraph(char c) { return c > 32; }
#endif
template < class T >
INLINE_V constexpr bool _is_integer = numeric_limits < T >::is_integer;
template < class T >
INLINE_V constexpr bool _is_signed = numeric_limits < T >::is_signed;
template < class T >
INLINE_V constexpr bool _is_unsigned = _is_integer < T > && !_is_signed < T >;
template <> INLINE_V constexpr bool _is_integer < __int128 > = true;
template <> INLINE_V constexpr bool _is_integer < __uint128_t > = true;
template <> INLINE_V constexpr bool _is_signed < __int128 > = true;
template <> INLINE_V constexpr bool _is_unsigned < __uint128_t > = true;
#undef INLINE_V
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();
}
#ifdef IN_HAS_NEG
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 >
#else
template < class T, enable_if_t < _is_integer < T >, int > = 0 >
#endif
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); }
#ifdef OUT_HAS_NEG
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 >
#else
template < class T, enable_if_t < _is_integer < T >, int > = 0 >
#endif
inline void write(T x)
{
char buffer[numeric_limits < T >::digits10 + 1]; 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) { print(x), pc(32), print(y...); }
template < class ...T >
inline void print_cstr(const char *x, const T *...y) { print_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 namespace FastIO;
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:
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(1ll * 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 = 1ll * 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; for ( ; y ; y >>= 1, x *= x ) if ( y & 1 ) z *= 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 < 998244353 >;
struct binom
{
MI fac[509], ifac[509];
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 binom.fac[x]; }
inline MI ifac(int x) { return binom.ifac[x]; }
inline MI c(int x, int y) { return x >= y && y >= 0 ? fac(x) * ifac(y) * ifac(x - y) : 0; }
int n, m, a[509], s[509], cnt; MI dp[509][509];
int main()
{
read(n);
For(i, 1, n) read(a[i]), s[i] = s[i - 1] + a[i];
m = s[n], dp[0][0] = 1;
For(i, 1, n) For(j, s[i - 1], m)
{
cnt = j - s[i - 1];
if ( cnt >= a[i] ) dp[i][j] += dp[i - 1][j];
For(k, 1, a[i]) For(jj, j + k, m) dp[i][jj] += dp[i - 1][j] * c(jj - j - 1, k - 1);
}
return println(dp[n][m].v), 0;
}
// 想上GM捏 想上GM捏 想上GM捏 想上GM捏 想上GM捏
// 伊娜可爱捏 伊娜贴贴捏
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 4392kb
input:
4 1 1 1 1
output:
14
result:
ok 1 number(s): "14"
Test #2:
score: -100
Wrong Answer
time: 91ms
memory: 4424kb
input:
300 0 5 2 2 1 0 3 2 2 5 2 1 1 2 1 3 2 3 2 0 0 0 0 1 2 2 3 0 2 2 3 2 0 2 3 0 6 0 0 2 0 1 3 2 1 1 1 3 4 0 1 0 4 1 1 1 1 1 1 2 3 2 1 2 3 2 3 0 5 3 3 2 0 1 1 0 2 1 1 2 0 0 2 1 1 3 2 2 1 2 1 3 0 3 0 1 2 2 0 5 0 2 2 0 0 0 1 2 1 4 2 1 1 0 3 0 2 0 3 1 1 2 0 2 1 1 0 2 0 1 2 2 3 3 1 1 1 1 0 1 3 3 1 0 2 2 4 2 ...
output:
876908700
result:
wrong answer 1st numbers differ - expected: '507010274', found: '876908700'