QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#134130 | #6756. 桂花树 | Talaodi | 100 ✓ | 273ms | 29644kb | C++14 | 8.6kb | 2023-08-03 08:01:15 | 2023-08-03 08:01:16 |
Judging History
answer
#include <bits/stdc++.h>
namespace IO {
template <class Stream>
Stream& fmtbase(Stream& out, const char* format) {
for (; *format; format++) {
if (*format == '{' && *(format + 1) == '}') {
throw std::invalid_argument("Error Number of Parameters!");
}
out << *format;
}
return out;
}
template <class Stream, class Fst, class... Nxt>
Stream& fmtbase(Stream& out, const char* format, const Fst& value, const Nxt&... nxt) {
for (; *format; format++) {
if (*format == '{' && *(format + 1) == '}') {
out << value;
return fmtbase(out, format + 2, nxt...);
}
out << *format;
}
throw std::invalid_argument("Error Number of Parameters!");
}
template <class... Ps>
std::string to_string(const char* format, const Ps&... ps) {
std::stringstream ss;
fmtbase(ss, format, ps...);
return ss.str();
}
template <class... Ps>
std::ostream& fmtout(const char* format, const Ps&... ps) {
return fmtbase(std::cout, format, ps...);
}
template <class... Ps>
std::ostream& fmterr(const char* format, const Ps&... ps) {
return fmtbase(std::cerr, format, ps...);
}
std::istream& allin() {
return std::cin;
}
template <class Fst, class ... Nxt>
std::istream& allin(Fst& fst, Nxt&... nxt) {
std::cin >> fst;
return allin(nxt...);
}
template <class Iter>
std::istream& rangin(Iter begin, Iter end) {
while (begin != end) {
std::cin >> *begin;
begin++;
}
return std::cin;
}
namespace Fast {
bool sync = false;
char buf[1 << 23];
char *p1 = buf, *p2 = buf;
void sync_with_ios(bool s) {
sync = s;
}
char getchar() {
if (sync) {
return (char) std::cin.get();
}
else {
if (p1 == p2) {
p1 = buf;
p2 = p1 + fread(buf, 1, 1 << 22, stdin);
}
if (p1 == p2) {
return EOF;
}
else {
char res = *p1;
p1++;
return res;
}
}
}
void read() { }
template <class T, class... U>
void read(T& x, U&... us) {
x = 0;
T pos = 1;
char c = getchar();
while (!isdigit(c)) {
if (c == '-') {
pos = -1;
}
c = getchar();
}
while (isdigit(c)) {
x = 10 * x + c - '0';
c = getchar();
}
x *= pos;
read(us...);
}
template <class T>
void write(const T& t) {
if (t > 10) {
write(t / 10);
}
std::cout << (int) (t % 10);
}
}
}
namespace Solve {
#define int long long
using namespace IO;
using ll = long long;
using ul = unsigned long long;
using db = double;
using ld = long double;
using ui = unsigned int;
using ib = __int128;
using ub = __uint128_t;
int const INF = std::numeric_limits<int>::max();
int const NINF = std::numeric_limits<int>::min();
ll const LINF = std::numeric_limits<ll>::max();
ll const LNINF = std::numeric_limits<ll>::min();
ld const EPS = 1e-6;
template <class T>
inline int isz(const T& v) {
return v.size();
}
template <class T>
inline T& ckmx(T& a, T b) {
return a < b ? (a = b) : a;
}
template <class T>
inline T& ckmi(T& a, T b) {
return a > b ? (a = b) : a;
}
template <int M>
struct ModInt {
static int const MOD = M;
int v;
ModInt() : v(0) { }
ModInt(long long v) {
if (-MOD <= v && v < 2 * MOD) {
if (v >= MOD) {
v -= MOD;
}
else if (v < 0) {
v += MOD;
}
}
else {
v %= MOD;
if (v < 0) {
v += MOD;
}
}
this->v = v;
}
ModInt operator++(signed) {
auto t = *this;
operator+=(1);
return t;
}
ModInt& operator++() {
operator+=(1);
return *this;
}
ModInt operator--(signed) {
auto t = *this;
operator-=(1);
return t;
}
ModInt& operator--() {
operator-=(1);
return *this;
}
ModInt& operator+=(const ModInt& rhs) {
v = v + rhs.v >= MOD ? v + rhs.v - MOD : v + rhs.v;
return *this;
}
friend ModInt operator+(const ModInt& lhs, const ModInt& rhs) {
ModInt res = lhs;
res += rhs;
return res;
}
ModInt& operator-=(const ModInt& rhs) {
v = v - rhs.v < 0 ? v - rhs.v + MOD : v - rhs.v;
return *this;
}
friend ModInt operator-(const ModInt& lhs, const ModInt& rhs) {
ModInt res = lhs;
res -= rhs;
return res;
}
ModInt& operator*=(const ModInt& rhs) {
v = 1ll * v * rhs.v % MOD;
return *this;
}
friend ModInt operator*(const ModInt& lhs, const ModInt& rhs) {
ModInt res = lhs;
res *= rhs;
return res;
}
ModInt fpow(long long p) const {
if (p < 0) {
return fpow(-p).inv();
}
else if (!p) {
return 1;
}
else if (p == 1) {
return *this;
}
else if (p == 2) {
return *this * *this;
}
else {
return fpow(p / 2).fpow(2) * fpow(p % 2);
}
}
friend bool operator==(const ModInt& a, const ModInt& b) {
return a.v == b.v;
}
friend bool operator!=(const ModInt& a, const ModInt& b) {
return a.v != b.v;
}
friend ModInt operator-(const ModInt& a) {
ModInt res;
if (a.v == 0) {
return 0;
}
res.v = MOD - a.v;
return res;
}
ModInt inv() const {
return fpow(MOD - 2);
}
ModInt operator/=(const ModInt& rhs) {
// O(log MOD)
return operator*=(rhs.inv());
}
friend ModInt operator/(const ModInt& lhs, const ModInt& rhs) {
ModInt res = lhs;
res /= rhs;
return res;
}
bool is_square() const {
return v == 0 || fpow((MOD - 1) / 2).v == 1;
}
ModInt sqrt() const {
static std::mt19937 mt(42334435);
static ModInt isq;
assert(is_square());
struct Complex {
ModInt a, b;
Complex operator*(const Complex& rhs) const {
return { a * rhs.a + isq * b * rhs.b, a * rhs.b + b * rhs.a };
}
Complex fpow(int n) {
if (!n) {
return { 1, 0 };
}
else if (n == 1) {
return *this;
}
else if (n == 2) {
return operator*(*this);
}
else {
return fpow(n / 2).fpow(2) * fpow(n % 2);
}
}
};
if (v == 0) {
return 0;
}
ModInt b;
while (true) {
b = mt() % MOD;
if (!(b * b - *this).is_square()) {
break;
}
}
isq = b * b - *this;
Complex c = { b, 1 };
auto res = c.fpow((MOD + 1) / 2).a;
return std::min(res.v, MOD - res.v);
}
};
template <int MOD>
std::istream& operator>>(std::istream& in, ModInt<MOD>& mint) {
long long v;
in >> v;
mint = ModInt<MOD>(v);
return in;
}
template <int MOD>
std::ostream& operator<<(std::ostream& out, const ModInt<MOD>& mint) {
return out << mint.v;
}
template <class T, int B>
struct FastPow {
T baby[B + 1];
T gaint[B + 1];
FastPow(T b) {
baby[0] = 1;
for (int i = 1; i <= B; i++) {
baby[i] = baby[i - 1] * b;
}
gaint[0] = 1;
for (int i = 1; i <= B; i++) {
gaint[i] = gaint[i - 1] * baby[B];
}
}
T get(int n) {
return gaint[n / B] * baby[n % B];
}
};
int const MOD = 1e9 + 7;
template <int M>
const int ModInt<M>::MOD;
using Mint = ModInt<MOD>;
int const K = 10;
int const M = 3010;
Mint f[M + 1][1 << K];
int n, m, k;
void main() {
std::cin >> n >> m >> k;
for (int i = 2; i <= n; i++) {
int f;
std::cin >> f;
}
f[0][0] = 1;
for (int i = 0; i < m; i++) {
for (int s = 0; s < (1 << k); s++) {
if (f[i][s] == 0) {
continue;
}
if (s & 1) {
f[i + 1][s >> 1] += f[i][s];
}
else {
int c = n + i + __builtin_popcount(s);
f[i + 1][s >> 1] += f[i][s] * (2 * c - 1);
int ns = s >> 1;
for (int j = 0; j < k; j++) {
if (!((ns >> j) & 1)) {
f[i + 1][ns | (1 << j)] += f[i][s] * (c - 1);
}
}
}
}
}
fmtout("{}\n", f[m][0]);
}
void init() {
}
void clear() {
for (int i = 0; i <= m; i++) {
for (int s = 0; s < (1 << k); s++) {
f[i][s] = 0;
}
}
n = m = k = 0;
}
}
signed main() {
#ifndef ONLINE_JUDGE
auto input_file = freopen("d.in", "r", stdin);
auto output_file = freopen("d.out", "w", stdout);
#endif
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
int t = 1;
std::cin >> t >> t;
Solve::init();
for (int id = 1; id <= t; id++) {
Solve::main();
Solve::clear();
}
#ifndef ONLINE_JUDGE
std::cout.flush();
fclose(input_file);
fclose(output_file);
#endif
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 5
Accepted
time: 1ms
memory: 28052kb
input:
1 15 4 2 9 1 2 3 4 4 1 1 1 1 4 3 10 1 2 3 4 2 10 1 2 3 2 3 0 1 2 2 8 1 2 4 10 1 3 3 0 1 2 3 2 0 1 1 2 2 0 1 2 4 9 1 4 2 0 1 1 1 2 4 1 1 4 4 8 1 1 1 3 3 0 1 2
output:
66 10132 787 66 105 16 1296 315 35 15 1296 63 1110 11384 315
result:
ok 15 numbers
Test #2:
score: 5
Accepted
time: 1ms
memory: 28848kb
input:
2 15 4 2 0 1 1 1 3 4 8 1 2 2 2 9 1 3 4 0 1 1 4 2 9 1 1 1 3 4 2 1 1 3 3 10 1 1 3 3 0 1 2 3 2 0 1 1 3 2 0 1 1 3 4 2 1 2 2 2 0 1 2 2 0 1 4 4 8 1 1 2 3 2 0 1 2
output:
63 4553 16 3465 66 4347 366 315 35 35 4347 15 15 11384 35
result:
ok 15 numbers
Test #3:
score: 5
Accepted
time: 19ms
memory: 29292kb
input:
3 15 25363 0 10 1 2 2 4 5 6 5 7 5 7 7 8 13 11 13 12 17 14 19 20 20 22 23 24 22 26 26 24 28 28 30 32 32 30 34 33 35 34 38 37 41 41 40 40 42 46 45 44 47 49 51 49 51 54 54 56 55 58 57 59 60 62 60 61 64 65 63 65 68 66 70 68 69 74 75 72 76 77 78 77 77 78 79 84 83 83 85 87 89 90 91 90 90 91 93 93 97 95 98...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
result:
ok 15 numbers
Test #4:
score: 5
Accepted
time: 6ms
memory: 28532kb
input:
4 15 95 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 81 1 0 1 1 3 3 2 4 4 4 7 8 8 11 11 12 15 16 17 18 19 17 19 22 20 22 24 25 27 24 25 26 28 29 32 33 32...
output:
189 161 157 183 179 179 185 165 161 179 191 159 199 177 195
result:
ok 15 numbers
Test #5:
score: 5
Accepted
time: 12ms
memory: 29556kb
input:
5 15 24238 1 9 1 2 2 3 2 3 7 6 6 8 11 8 13 14 14 13 14 15 15 20 17 21 19 24 25 22 23 28 27 29 28 31 32 34 35 32 35 35 39 37 38 42 39 41 43 42 47 47 45 48 49 52 50 52 51 55 53 57 58 58 60 58 60 64 62 66 66 65 65 69 68 68 73 71 72 73 75 78 77 76 78 82 81 84 82 85 84 87 86 89 90 90 90 90 91 93 94 94 98...
output:
48475 54131 56879 54501 49951 55359 46639 52775 56387 53417 55987 58213 48849 46865 56865
result:
ok 15 numbers
Test #6:
score: 5
Accepted
time: 1ms
memory: 27572kb
input:
6 15 90 2 0 1 1 3 3 4 6 3 5 6 1 4 8 6 3 7 2 8 17 12 1 15 8 10 17 4 7 22 1 16 15 13 17 6 24 18 20 29 24 5 37 26 19 1 36 10 11 1 32 12 29 25 36 43 25 36 35 27 30 48 13 57 43 3 48 20 49 10 42 33 32 15 67 3 72 18 59 45 65 22 47 21 76 44 36 70 31 40 36 75 97 2 10 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
32399 37731 39999 28223 29668 37731 36193 26895 35436 39301 33946 31771 30975 24335 36958
result:
ok 15 numbers
Test #7:
score: 5
Accepted
time: 8ms
memory: 28968kb
input:
7 15 23937 2 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 ...
output:
291919861 146761194 947431229 721917569 513436690 452531920 95169750 435600974 157568937 921186289 544059002 432348666 320565654 309379121 377927681
result:
ok 15 numbers
Test #8:
score: 5
Accepted
time: 0ms
memory: 28460kb
input:
8 15 1 89 0 1 88 0 1 86 0 1 81 0 1 89 0 1 88 0 1 85 0 1 88 0 1 99 0 1 93 0 1 94 0 1 79 0 1 97 0 1 88 0 1 96 0
output:
643555007 320020087 809556406 776533926 643555007 320020087 414090976 320020087 356146221 792287148 157695640 15616881 389622706 320020087 654868516
result:
ok 15 numbers
Test #9:
score: 5
Accepted
time: 1ms
memory: 27888kb
input:
9 15 1 85 0 1 86 0 1 90 0 1 87 0 1 87 0 1 91 0 1 81 0 1 79 0 1 86 0 1 80 0 1 81 0 1 88 0 1 98 0 1 89 0 1 78 0
output:
414090976 809556406 196345448 53257258 53257258 538525843 776533926 15616881 809556406 483084065 776533926 320020087 976427145 643555007 299462530
result:
ok 15 numbers
Test #10:
score: 5
Accepted
time: 0ms
memory: 28484kb
input:
10 15 1 2600 0 1 2562 0 1 2885 0 1 2926 0 1 2980 0 1 2796 0 1 2809 0 1 2441 0 1 2964 0 1 2384 0 1 2634 0 1 2284 0 1 2732 0 1 2525 0 1 2635 0
output:
980378455 337526154 558193103 125913045 124855760 503883918 199525532 902720193 515375300 777422724 363348923 334557029 939566213 938891504 485461889
result:
ok 15 numbers
Test #11:
score: 5
Accepted
time: 7ms
memory: 28224kb
input:
11 15 1 97 8 1 98 8 1 75 9 1 86 10 1 91 10 1 80 10 1 99 10 1 75 10 1 81 3 1 86 8 1 76 10 1 79 9 1 77 9 1 79 8 1 92 10
output:
201967493 593344966 454636651 58812991 509364979 455029717 399412420 697505560 426878348 397782687 146643903 719871243 754719823 132594531 954628592
result:
ok 15 numbers
Test #12:
score: 5
Accepted
time: 243ms
memory: 28780kb
input:
12 15 1 2419 9 1 3000 8 1 2952 9 1 2911 10 1 2596 8 1 2997 10 1 2479 10 1 2447 10 1 2504 8 1 2325 9 1 2473 10 1 2674 8 1 2817 9 1 2303 8 1 2253 6
output:
897921773 493618043 502033461 163722526 998027298 171201566 988250983 759578319 522233752 644875547 630714473 82369707 754521000 259048908 717777794
result:
ok 15 numbers
Test #13:
score: 5
Accepted
time: 1ms
memory: 29596kb
input:
13 15 96 77 0 1 1 2 2 3 3 4 4 5 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 8 8 65 17 9 33 83 76 52 42 17 56 39 82 26 53 89 96 0 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 ...
output:
875522633 817514869 984115449 171618725 413906221 67403237 626927815 102038917 731937401 81736574 147698013 5718686 570093465 291610 736092684
result:
ok 15 numbers
Test #14:
score: 5
Accepted
time: 1ms
memory: 29644kb
input:
14 15 79 92 0 1 2 1 3 2 5 6 6 6 10 7 8 10 13 14 13 15 16 17 18 17 18 21 24 25 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 18 33 33 18 9 48 19 2 6 12 28 3 22 50 5 24 14 10 15 42 11 44 36 38 58 21 9 96 81 0 1 2 3 4 3 2 4 7 7 1 7 10 12 13 1 9 14 6 13 18 4 2 4 14 25 3 3...
output:
69626057 106800079 696160675 125365500 105229737 980457872 857341479 727730150 931017912 72350415 700427628 857341479 458562426 105229737 33015237
result:
ok 15 numbers
Test #15:
score: 5
Accepted
time: 16ms
memory: 28596kb
input:
15 15 27219 2720 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50...
output:
512213075 634563835 412223891 885815756 909933373 460122433 143582817 318866407 952581018 559698410 15451972 798343658 240180291 40997907 507956430
result:
ok 15 numbers
Test #16:
score: 5
Accepted
time: 9ms
memory: 27948kb
input:
16 15 23470 2270 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50...
output:
613353516 498696894 341174230 524070747 458732519 657246209 497631698 460156266 650070681 438365748 579953962 638226266 303839474 655729798 51100917
result:
ok 15 numbers
Test #17:
score: 5
Accepted
time: 6ms
memory: 27884kb
input:
17 15 94 82 9 1 2 2 3 3 6 6 8 6 10 7 10 13 10 14 14 16 17 18 17 20 18 23 24 22 26 25 27 25 26 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 59 39 56 52 21 51 66 59 33 68 29 34 62 47 59 76 54 72 40 40 3 4 63 33 44 73 59 18 19 70 25 77 93 86 8 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
57879436 325557854 91787824 410242939 853965973 142189519 742252318 181854803 57653454 102825828 223733805 982035357 963632678 929397289 890046592
result:
ok 15 numbers
Test #18:
score: 5
Accepted
time: 3ms
memory: 29632kb
input:
18 15 78 96 1 1 1 2 2 3 3 4 4 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 7 7 52 54 22 16 21 56 64 32 42 64 52 49 19 87 86 9 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
76805686 353383610 224346320 111078253 766068511 881559887 431130327 846136820 658010636 340111764 612573560 824188027 435154505 227628660 45266228
result:
ok 15 numbers
Test #19:
score: 5
Accepted
time: 241ms
memory: 28524kb
input:
19 15 26104 2591 3 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50...
output:
352998989 343378163 332642314 329512384 132607327 87163047 200914906 690708263 643035325 490644560 544357196 370133318 274907996 878486015 823925934
result:
ok 15 numbers
Test #20:
score: 5
Accepted
time: 273ms
memory: 29240kb
input:
20 15 22821 2558 8 1 1 1 3 2 4 2 5 5 5 7 7 13 4 15 12 1 17 15 6 10 10 13 20 20 1 16 14 9 9 28 24 14 28 2 28 35 20 30 37 1 9 21 35 42 23 41 11 15 29 10 1 13 6 24 11 11 46 32 39 32 10 59 57 20 24 51 24 60 28 65 16 31 42 25 12 27 28 53 49 15 12 58 73 83 47 7 71 2 2 26 57 82 61 17 17 48 96 23 83 2 41 59...
output:
852082753 663863799 567411082 526354875 894631436 262990076 719766589 173209722 880032338 29895723 506677794 954758703 758235022 133292061 393482362
result:
ok 15 numbers
Extra Test:
score: 0
Extra Test Passed