QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#443057 | #8529. Balance of Permutation | ucup-team896# | AC ✓ | 2017ms | 129300kb | C++23 | 7.9kb | 2024-06-15 14:15:47 | 2024-06-15 14:15:48 |
Judging History
answer
/* _ _ _ _ __ __ __
/ \ _ _ | |_ | |__ ___ _ __ _ ___ _ __ ___ | | __ / /_ / /_ / /_
/ _ \ | | | | | __| | '_ \ / _ \ | '__| (_) / __| | '_ ` _ \ | |/ / | '_ \ | '_ \ | '_ \
/ ___ \ | |_| | | |_ | | | | | (_) | | | _ | (__ | | | | | | | < | (_) | | (_) | | (_) |
/_/ \_\ \__,_| \__| |_| |_| \___/ |_| (_) \___| |_| |_| |_| |_|\_\ \___/ \___/ \___/
[Created Time: 2024-06-15 13:49:50]
[Last Modified Time: 2024-06-15 14:15:10] */
#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
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;
int n, b, ans[39], cs, ct; bool used[39], s[39], t[39]; __int128 k, nw, o, dp[39][39][39][909];
inline __int128 calc(int b)
{
cs = ct = 0;
For(i, 0, n)
{
if ( i ) cs += s[i], ct += t[i];
For(j, 0, cs) For(k, 0, ct) For(ii, 0, b - j - k) dp[i][j][k][ii] = 0;
}
****dp = 1, cs = ct = 0;
For(i, 1, n)
{
For(j, 0, cs) For(k, 0, ct) For(ii, 0, b - j - k) if ( o = dp[i - 1][j][k][ii] )
{
if ( s[i] && t[i] ) dp[i][j + 1][k + 1][ii + j + k] += o,
j && k && ( dp[i][j - 1][k - 1][ii + j + k] += o * j * k ),
dp[i][j ][k ][ii + j + k] += o * ( j + k + 1 );
else if ( s[i] ) dp[i][j + 1][k ][ii + j + k] += o,
k && ( dp[i][j ][k - 1][ii + j + k] += o * k );
else if ( t[i] ) dp[i][j ][k + 1][ii + j + k] += o,
j && ( dp[i][j - 1][k ][ii + j + k] += o * j );
else dp[i][j ][k ][ii + j + k] += o;
}
cs += s[i], ct += t[i];
}
return dp[n][0][0][b];
}
int main()
{
read(n, b, k), k--;
For(i, 1, n) For(j, 1, n) if ( !used[j] && b >= abs(j - i) )
{
For(ii, 1, n) s[ii] = !used[ii] && ii != j, t[ii] = ii > i;
nw = calc(b - abs(j - i));
if ( k >= nw ) k -= nw;
else { used[j] = true, ans[i] = j, b -= abs(j - i); break; }
}
For(i, 1, n) write(ans[i], i == n ? '\n' : ' ');
return 0;
}
// 想上GM捏 想上GM捏 想上GM捏 想上GM捏 想上GM捏
// 伊娜可爱捏 伊娜贴贴捏
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 22136kb
input:
6 6 6
output:
1 2 6 3 4 5
result:
ok 6 numbers
Test #2:
score: 0
Accepted
time: 311ms
memory: 98600kb
input:
30 300 3030303030303030303030
output:
1 2 3 4 9 23 20 28 24 16 21 17 27 29 8 26 25 30 19 18 22 12 7 13 6 10 5 15 14 11
result:
ok 30 numbers
Test #3:
score: 0
Accepted
time: 1ms
memory: 5628kb
input:
1 0 1
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 1ms
memory: 9680kb
input:
2 0 1
output:
1 2
result:
ok 2 number(s): "1 2"
Test #5:
score: 0
Accepted
time: 0ms
memory: 9740kb
input:
2 2 1
output:
2 1
result:
ok 2 number(s): "2 1"
Test #6:
score: 0
Accepted
time: 2ms
memory: 14012kb
input:
5 8 3
output:
1 5 4 2 3
result:
ok 5 number(s): "1 5 4 2 3"
Test #7:
score: 0
Accepted
time: 2ms
memory: 14304kb
input:
7 20 100
output:
3 6 7 4 1 5 2
result:
ok 7 numbers
Test #8:
score: 0
Accepted
time: 0ms
memory: 16012kb
input:
7 2 6
output:
2 1 3 4 5 6 7
result:
ok 7 numbers
Test #9:
score: 0
Accepted
time: 2ms
memory: 10352kb
input:
7 24 1
output:
4 5 6 7 1 2 3
result:
ok 7 numbers
Test #10:
score: 0
Accepted
time: 0ms
memory: 4396kb
input:
7 22 360
output:
7 6 4 3 5 2 1
result:
ok 7 numbers
Test #11:
score: 0
Accepted
time: 0ms
memory: 4348kb
input:
7 20 358
output:
5 7 2 4 6 3 1
result:
ok 7 numbers
Test #12:
score: 0
Accepted
time: 0ms
memory: 15576kb
input:
10 48 10001
output:
7 5 8 9 6 10 3 4 1 2
result:
ok 10 numbers
Test #13:
score: 0
Accepted
time: 2ms
memory: 7504kb
input:
10 42 10101
output:
3 9 6 8 10 5 7 2 1 4
result:
ok 10 numbers
Test #14:
score: 0
Accepted
time: 196ms
memory: 50252kb
input:
25 300 1
output:
7 14 15 16 17 18 19 20 21 22 23 24 25 1 2 3 4 5 6 8 9 10 11 12 13
result:
ok 25 numbers
Test #15:
score: 0
Accepted
time: 352ms
memory: 70096kb
input:
25 300 283788388040048639877
output:
25 24 23 22 21 20 19 18 17 16 11 12 13 14 15 10 9 8 7 5 6 4 2 1 3
result:
ok 25 numbers
Test #16:
score: 0
Accepted
time: 339ms
memory: 75152kb
input:
26 302 105773752969551707419545
output:
19 22 25 13 17 18 23 20 10 26 16 6 5 11 14 12 24 4 3 21 1 15 7 8 2 9
result:
ok 26 numbers
Test #17:
score: 0
Accepted
time: 387ms
memory: 81588kb
input:
27 308 8781128321749037280676555
output:
16 18 17 21 25 6 20 24 22 15 27 5 7 8 2 9 26 13 1 3 14 10 23 19 4 11 12
result:
ok 27 numbers
Test #18:
score: 0
Accepted
time: 377ms
memory: 83036kb
input:
28 304 806517199954337651602356955
output:
12 17 5 16 23 26 25 15 20 2 19 7 22 24 6 13 11 10 28 8 1 21 18 14 27 3 4 9
result:
ok 28 numbers
Test #19:
score: 0
Accepted
time: 614ms
memory: 96884kb
input:
29 322 40281026669581503094652149519
output:
16 21 10 25 17 29 9 28 2 8 26 27 22 4 3 5 18 14 19 1 23 20 15 11 13 7 6 12 24
result:
ok 29 numbers
Test #20:
score: 0
Accepted
time: 1306ms
memory: 118128kb
input:
30 400 46479902466857426153849991132
output:
25 19 30 29 9 20 26 21 14 27 28 10 22 11 24 2 7 4 18 17 5 13 12 6 8 1 15 23 16 3
result:
ok 30 numbers
Test #21:
score: 0
Accepted
time: 1315ms
memory: 125492kb
input:
30 450 1140008168482799670544355
output:
26 16 17 18 19 20 21 22 23 24 25 27 28 29 30 1 2 3 5 9 4 8 14 10 6 11 12 15 7 13
result:
ok 30 numbers
Test #22:
score: 0
Accepted
time: 107ms
memory: 82300kb
input:
30 150 480087379811286955791425915
output:
7 4 8 5 16 3 1 12 13 11 9 10 15 25 18 17 20 30 28 2 6 14 23 21 24 26 27 22 19 29
result:
ok 30 numbers
Test #23:
score: 0
Accepted
time: 111ms
memory: 82264kb
input:
30 150 480087379811286955791439470
output:
7 4 8 5 16 3 1 12 13 11 9 10 15 25 18 17 20 30 28 2 19 6 22 24 21 23 26 14 29 27
result:
ok 30 numbers
Test #24:
score: 0
Accepted
time: 1315ms
memory: 126888kb
input:
30 440 41509275104334759322587324
output:
22 23 20 24 18 30 19 26 21 28 4 29 17 25 27 16 3 1 2 5 8 13 10 15 7 12 9 14 11 6
result:
ok 30 numbers
Test #25:
score: 0
Accepted
time: 1313ms
memory: 129300kb
input:
30 450 1140008168482800727111311
output:
26 16 17 18 19 20 21 22 23 24 25 27 28 29 30 1 2 5 7 14 4 15 8 11 3 13 10 9 6 12
result:
ok 30 numbers
Test #26:
score: 0
Accepted
time: 1256ms
memory: 122044kb
input:
30 400 52289890275214604423031772929
output:
26 27 29 21 28 16 18 11 2 25 24 23 6 30 20 13 17 10 15 4 9 12 8 22 19 1 5 7 3 14
result:
ok 30 numbers
Test #27:
score: 0
Accepted
time: 0ms
memory: 26248kb
input:
30 0 1
output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
result:
ok 30 numbers
Test #28:
score: 0
Accepted
time: 1138ms
memory: 122416kb
input:
30 450 1
output:
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
result:
ok 30 numbers
Test #29:
score: 0
Accepted
time: 2017ms
memory: 126780kb
input:
30 450 1710012252724199424000000
output:
30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
result:
ok 30 numbers
Test #30:
score: 0
Accepted
time: 1831ms
memory: 124936kb
input:
30 450 1692383260428073656742269
output:
30 27 26 28 18 29 21 19 25 17 20 16 24 22 23 7 13 4 6 3 5 12 1 15 14 9 11 8 2 10
result:
ok 30 numbers
Test #31:
score: 0
Accepted
time: 943ms
memory: 105984kb
input:
30 302 5918364042599361729860937331200
output:
30 29 28 27 26 25 14 8 9 10 11 12 13 7 15 16 17 18 19 20 21 22 23 24 6 5 4 3 2 1
result:
ok 30 numbers
Test #32:
score: 0
Accepted
time: 382ms
memory: 95812kb
input:
30 254 2256781660157136563723839089600
output:
25 2 3 12 7 16 19 8 22 6 11 17 27 26 10 24 15 21 20 18 28 9 30 23 14 13 5 29 4 1
result:
ok 30 numbers
Test #33:
score: 0
Accepted
time: 1660ms
memory: 122692kb
input:
30 448 3131906441000512625049600
output:
23 20 28 18 26 30 19 29 27 22 17 24 21 25 2 13 16 15 14 12 11 10 9 8 7 6 5 4 3 1
result:
ok 30 numbers
Test #34:
score: 0
Accepted
time: 0ms
memory: 26776kb
input:
30 2 20
output:
1 2 3 4 5 6 7 8 9 11 10 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
result:
ok 30 numbers
Test #35:
score: 0
Accepted
time: 0ms
memory: 24832kb
input:
30 2 29
output:
2 1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
result:
ok 30 numbers
Extra Test:
score: 0
Extra Test Passed