QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#662718 | #8702. 狼人杀 | peaneval_kala | 100 ✓ | 193ms | 11220kb | C++23 | 12.0kb | 2024-10-21 09:27:51 | 2024-10-21 09:27:51 |
Judging History
answer
#pragma GCC optimize(3, "unroll-loops", "no-stack-protector")
#define atsum(l, r) accumulate(l, r, 0)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/hash_policy.hpp>
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr int inf = 0x3f3f3f3f;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
template <typename T>
inline void chkmin(T &x, T y) {
x = min(x, y);
}
template <typename T>
inline void chkmax(T &x, T y) {
x = max(x, y);
}
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 {
~_auto_flush() {
fwrite(_write_buffer, 1, _write_ptr - _write_buffer, stdout);
}
} _auto_flush;
#endif
#ifdef CHK_EOF
inline bool _isdigit(char c) { return (c & 16) && c != EOF; }
inline bool _isgraph(char c) { return c > 32 && c != EOF; }
#else
inline bool _isdigit(char c) { return c & 16; }
inline 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);
}
} // namespace FastIO
using namespace FastIO;
template <typename T>
inline void clear(T &x) {
T y;
swap(x, y);
}
template <uint32_t mod = 1000000007>
class Modint {
private:
static constexpr uint32_t get_r() {
uint32_t ret = mod;
for (int i = 0; i < 4; i++) ret *= 2 - mod * ret;
return ret;
}
static constexpr uint32_t r = get_r();
static constexpr uint32_t n2 = -uint64_t(mod) % mod;
static_assert(r * mod == 1 && mod < (1 << 30) && mod & 1);
uint32_t data;
public:
constexpr Modint() : data(0) {}
template <class int_t>
constexpr Modint(const int_t x)
: data(reduce(
uint64_t((sizeof(int_t) < sizeof(uint32_t) ? x : x % int_t(mod)) +
mod) *
n2)){};
static constexpr uint32_t reduce(const uint64_t x) {
return (x + uint64_t(uint32_t(x) * (-r)) * mod) >> 32;
}
constexpr Modint &operator+=(const Modint &r) {
if (int32_t(data += r.data - 2 * mod) < 0) {
data += 2 * mod;
}
return *this;
}
constexpr Modint &operator-=(const Modint &r) {
if (int32_t(data -= r.data) < 0) {
data += 2 * mod;
}
return *this;
}
constexpr Modint &operator*=(const Modint &r) {
return data = reduce((uint64_t)data * r.data), *this;
}
constexpr Modint &operator/=(const Modint &r) { return *this *= r.inv(); }
constexpr friend Modint operator+(Modint l, const Modint &r) {
return l += r;
}
constexpr friend Modint operator-(Modint l, const Modint &r) {
return l -= r;
}
constexpr friend Modint operator*(Modint l, const Modint &r) {
return l *= r;
}
constexpr friend Modint operator/(Modint l, const Modint &r) {
return l /= r;
}
constexpr friend bool operator==(Modint l, const Modint &r) {
return l.value() == r.value();
}
constexpr Modint operator-() const { return Modint() - Modint(*this); }
template <class int_t>
constexpr Modint pow(int_t r) const {
Modint res(1), w(*this);
for (; r; r >>= 1, w *= w)
if (r & 1) res *= w;
return res;
}
constexpr Modint inv() const { return pow(mod - 2); }
constexpr uint32_t value() const {
uint32_t res = reduce(data);
return res >= mod ? res - mod : res;
}
};
const int P = 1000000007;
using modint = Modint<>;
const int N = 155;
int n, X, pu, p[N];
modint inv[N * N], ans;
int f[N][N * N / 2], g[N][N * N / 2];
int C[N];
inline void minusx(int &u, int v) {
if ((u -= v) < 0) u += 1000000007;
}
int main() {
read(n, X);
for (int i = 0; i <= n; i++) C[i] = i * (i + 1) / 2;
for (int i = 1; i <= n * n; i++) inv[i] = modint(i).inv();
f[X][n * (n + 1) / 2] = 1000000006;
for (int i = X + 1; i <= n; i++) {
for (int j = X; j < i; j++)
for (int k = 0; k <= n * (n + 1) / 2; k++)
if (f[j][k] || g[j][k]) {
minusx(f[i][k - C[i - j - 1]], f[j][k]);
minusx(g[i][k - C[i - j - 1]], g[j][k]);
minusx(g[i][k - C[i - j - 1]], 1ll * f[j][k] * (i - j - 1) % P);
}
}
for (int i = 1; i < X; i++) {
for (int j = X; j <= n; j++)
for (int k = 0; k <= n * (n + 1) / 2; k++)
if (f[j][k] || g[j][k]) {
minusx(f[i][k - i * (n - j + 1) - C[i - 1] - C[n - j]], f[j][k]);
minusx(g[i][k - i * (n - j + 1) - C[i - 1] - C[n - j]], g[j][k]);
minusx(g[i][k - i * (n - j + 1) - C[i - 1] - C[n - j]], 1ll * f[j][k] * (n - j + i - 1) % P);
}
for (int j = 1; j < i; j++)
for (int k = 0; k <= n * (n + 1) / 2; k++)
if (f[j][k] || g[j][k]) {
minusx(f[i][k - C[i - j - 1]], f[j][k]);
minusx(g[i][k - C[i - j - 1]], g[j][k]);
minusx(g[i][k - C[i - j - 1]], 1ll * f[j][k] * (i - j - 1) % P);
}
}
for (int i = X + 1; i <= n; i++)
for (int k = 0; k <= n * (n + 1) / 2; k++)
if (f[i][k] || g[i][k]) {
ans += modint(g[i][k]) * inv[k - X * (n - i + 1) - C[X - 1] - C[n - i]];
ans += modint(f[i][k]) * (n - i + X - 1) * inv[k - X * (n - i + 1) - C[X - 1] - C[n - i]];
}
for (int i = 1; i < X; i++)
for (int k = 0; k <= n * (n + 1) / 2; k++)
if (f[i][k] || g[i][k]) {
ans += modint(g[i][k]) * inv[k - C[X - i - 1]];
ans += modint(f[i][k]) * (X - i - 1) * inv[k - C[X - i - 1]];
}
println((ans * C[n] * inv[n - 1]).value());
return 0;
}
// 7 / 2
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 23
Accepted
Test #1:
score: 23
Accepted
time: 1ms
memory: 5772kb
input:
12 2
output:
183756997
result:
ok single line: '183756997'
Test #2:
score: 23
Accepted
time: 1ms
memory: 5676kb
input:
17 6
output:
97571903
result:
ok single line: '97571903'
Test #3:
score: 23
Accepted
time: 0ms
memory: 5836kb
input:
13 3
output:
209826617
result:
ok single line: '209826617'
Test #4:
score: 23
Accepted
time: 0ms
memory: 5708kb
input:
13 8
output:
176038768
result:
ok single line: '176038768'
Test #5:
score: 23
Accepted
time: 0ms
memory: 5684kb
input:
18 4
output:
288404061
result:
ok single line: '288404061'
Test #6:
score: 23
Accepted
time: 1ms
memory: 5788kb
input:
10 10
output:
219657163
result:
ok single line: '219657163'
Test #7:
score: 23
Accepted
time: 1ms
memory: 5684kb
input:
19 15
output:
590577825
result:
ok single line: '590577825'
Test #8:
score: 23
Accepted
time: 1ms
memory: 5768kb
input:
11 6
output:
488143489
result:
ok single line: '488143489'
Test #9:
score: 23
Accepted
time: 1ms
memory: 7684kb
input:
10 5
output:
470594541
result:
ok single line: '470594541'
Test #10:
score: 23
Accepted
time: 0ms
memory: 7776kb
input:
20 5
output:
582458555
result:
ok single line: '582458555'
Test #11:
score: 23
Accepted
time: 0ms
memory: 5812kb
input:
20 12
output:
648081410
result:
ok single line: '648081410'
Test #12:
score: 23
Accepted
time: 0ms
memory: 7732kb
input:
20 4
output:
335777285
result:
ok single line: '335777285'
Test #13:
score: 23
Accepted
time: 0ms
memory: 7792kb
input:
20 15
output:
389216500
result:
ok single line: '389216500'
Test #14:
score: 23
Accepted
time: 0ms
memory: 5812kb
input:
20 16
output:
582458555
result:
ok single line: '582458555'
Test #15:
score: 23
Accepted
time: 0ms
memory: 7784kb
input:
20 19
output:
589126150
result:
ok single line: '589126150'
Test #16:
score: 23
Accepted
time: 0ms
memory: 5916kb
input:
20 6
output:
389216500
result:
ok single line: '389216500'
Subtask #2:
score: 34
Accepted
Dependency #1:
100%
Accepted
Test #17:
score: 34
Accepted
time: 3ms
memory: 8184kb
input:
49 14
output:
486918542
result:
ok single line: '486918542'
Test #18:
score: 34
Accepted
time: 1ms
memory: 5856kb
input:
28 13
output:
642223597
result:
ok single line: '642223597'
Test #19:
score: 34
Accepted
time: 1ms
memory: 5896kb
input:
35 23
output:
842346505
result:
ok single line: '842346505'
Test #20:
score: 34
Accepted
time: 0ms
memory: 5940kb
input:
47 11
output:
583647040
result:
ok single line: '583647040'
Test #21:
score: 34
Accepted
time: 2ms
memory: 8120kb
input:
34 30
output:
990970048
result:
ok single line: '990970048'
Test #22:
score: 34
Accepted
time: 1ms
memory: 5796kb
input:
30 7
output:
393675971
result:
ok single line: '393675971'
Test #23:
score: 34
Accepted
time: 2ms
memory: 5880kb
input:
43 5
output:
737421246
result:
ok single line: '737421246'
Test #24:
score: 34
Accepted
time: 0ms
memory: 5936kb
input:
30 21
output:
254760745
result:
ok single line: '254760745'
Test #25:
score: 34
Accepted
time: 0ms
memory: 5888kb
input:
27 22
output:
266692865
result:
ok single line: '266692865'
Test #26:
score: 34
Accepted
time: 0ms
memory: 5884kb
input:
40 12
output:
133652311
result:
ok single line: '133652311'
Test #27:
score: 34
Accepted
time: 1ms
memory: 7904kb
input:
29 4
output:
873892090
result:
ok single line: '873892090'
Test #28:
score: 34
Accepted
time: 3ms
memory: 8164kb
input:
50 46
output:
267950067
result:
ok single line: '267950067'
Test #29:
score: 34
Accepted
time: 0ms
memory: 5932kb
input:
50 11
output:
423642322
result:
ok single line: '423642322'
Test #30:
score: 34
Accepted
time: 3ms
memory: 6108kb
input:
50 43
output:
625476642
result:
ok single line: '625476642'
Test #31:
score: 34
Accepted
time: 0ms
memory: 6060kb
input:
50 36
output:
767166129
result:
ok single line: '767166129'
Test #32:
score: 34
Accepted
time: 3ms
memory: 6172kb
input:
50 14
output:
357467965
result:
ok single line: '357467965'
Test #33:
score: 34
Accepted
time: 3ms
memory: 6048kb
input:
50 30
output:
219673347
result:
ok single line: '219673347'
Test #34:
score: 34
Accepted
time: 3ms
memory: 6148kb
input:
50 44
output:
392786132
result:
ok single line: '392786132'
Test #35:
score: 34
Accepted
time: 0ms
memory: 6108kb
input:
50 10
output:
848251616
result:
ok single line: '848251616'
Subtask #3:
score: 43
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Test #36:
score: 43
Accepted
time: 12ms
memory: 6652kb
input:
75 47
output:
668751416
result:
ok single line: '668751416'
Test #37:
score: 43
Accepted
time: 12ms
memory: 6516kb
input:
75 41
output:
310834114
result:
ok single line: '310834114'
Test #38:
score: 43
Accepted
time: 107ms
memory: 9192kb
input:
133 124
output:
57167600
result:
ok single line: '57167600'
Test #39:
score: 43
Accepted
time: 100ms
memory: 8896kb
input:
129 74
output:
751074385
result:
ok single line: '751074385'
Test #40:
score: 43
Accepted
time: 114ms
memory: 7964kb
input:
135 133
output:
759430862
result:
ok single line: '759430862'
Test #41:
score: 43
Accepted
time: 12ms
memory: 6660kb
input:
75 19
output:
967921272
result:
ok single line: '967921272'
Test #42:
score: 43
Accepted
time: 78ms
memory: 10628kb
input:
124 9
output:
641081661
result:
ok single line: '641081661'
Test #43:
score: 43
Accepted
time: 12ms
memory: 6692kb
input:
76 66
output:
465902083
result:
ok single line: '465902083'
Test #44:
score: 43
Accepted
time: 137ms
memory: 9652kb
input:
142 13
output:
12401929
result:
ok single line: '12401929'
Test #45:
score: 43
Accepted
time: 174ms
memory: 10380kb
input:
150 5
output:
388058135
result:
ok single line: '388058135'
Test #46:
score: 43
Accepted
time: 50ms
memory: 8144kb
input:
109 97
output:
381109644
result:
ok single line: '381109644'
Test #47:
score: 43
Accepted
time: 183ms
memory: 10124kb
input:
150 133
output:
174431234
result:
ok single line: '174431234'
Test #48:
score: 43
Accepted
time: 176ms
memory: 10032kb
input:
150 147
output:
198921722
result:
ok single line: '198921722'
Test #49:
score: 43
Accepted
time: 174ms
memory: 9984kb
input:
150 142
output:
631473185
result:
ok single line: '631473185'
Test #50:
score: 43
Accepted
time: 178ms
memory: 10080kb
input:
150 136
output:
743180069
result:
ok single line: '743180069'
Test #51:
score: 43
Accepted
time: 177ms
memory: 10468kb
input:
150 138
output:
621574340
result:
ok single line: '621574340'
Test #52:
score: 43
Accepted
time: 187ms
memory: 9984kb
input:
150 119
output:
872660153
result:
ok single line: '872660153'
Test #53:
score: 43
Accepted
time: 174ms
memory: 9412kb
input:
150 144
output:
939939060
result:
ok single line: '939939060'
Test #54:
score: 43
Accepted
time: 171ms
memory: 11220kb
input:
150 1
output:
166208360
result:
ok single line: '166208360'
Test #55:
score: 43
Accepted
time: 193ms
memory: 10108kb
input:
150 75
output:
353929212
result:
ok single line: '353929212'