QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#210841 | #5749. Directed Vertex Cacti | Hunster | AC ✓ | 139ms | 4148kb | C++14 | 3.3kb | 2023-10-11 20:35:45 | 2023-10-11 20:35:45 |
Judging History
answer
#include <bits/stdc++.h>
template <bool flag, typename T1, typename T2>
struct TemplateIf;
template <typename T1, typename T2>
struct TemplateIf<true, T1, T2> { using Type = T1; };
template <typename T1, typename T2>
struct TemplateIf<false, T1, T2> { using Type = T2; };
using i32 = int32_t;
using i64 = int64_t;
using i128 = __int128_t;
using u32 = uint32_t;
using u64 = uint64_t;
using u128 = __uint128_t;
template <typename T>
using Vec = std::vector<T>;
template <typename T, size_t... other>
struct ArraySwitch;
template <typename T, size_t size, size_t... other>
struct ArraySwitch<T, size, other...> { using Result = std::array<typename ArraySwitch<T, other...>::Result, size>; };
template <typename T, size_t size>
struct ArraySwitch<T, size> { using Result = typename std::array<T, size>; };
template <typename T, size_t... size>
using Arr = typename ArraySwitch<T, size...>::Result;
template <typename T>
using MaxHeap = std::priority_queue<T, Vec<T>, std::less<T>>;
template <typename T>
using MinHeap = std::priority_queue<T, Vec<T>, std::greater<T>>;
constexpr i32 inf32 = (i32)(1e9) + 9;
constexpr i64 inf64 = (i64)(1e18) + 18;
std::mt19937 rng { (std::random_device())() };
template <typename T>
inline T makeVec(T val) { return val; }
template <typename T, typename... Args>
inline auto makeVec(T val, size_t size, Args... rest) {
auto t = makeVec<T>(val, rest...);
return Vec<decltype(t)>(size, t);
}
inline i32 clz(u32 x) { return __builtin_clz(x); }
inline i32 clzll(u64 x) { return __builtin_clzll(x); }
inline i32 ctz(u32 x) { return __builtin_ctz(x); }
inline i32 ctzll(u64 x) { return __builtin_ctzll(x); }
inline i32 popcount(u32 x) { return __builtin_popcount(x); }
inline i32 popcountll(u64 x) { return __builtin_popcountll(x); }
template <typename T>
inline T _min(T a) { return a; }
template <typename T, typename... Args>
inline T _min(T a, T b, Args... args) { return _min<T>(std::min<T>(a, b), args...); }
template <typename T>
inline T _max(T a) { return a; }
template <typename T, typename... Args>
inline T _max(T a, T b, Args... args) { return _max<T>(std::max<T>(a, b), args...); }
constexpr i32 num_big_primes = 10;
constexpr Arr<i32, num_big_primes> big_primes { 99990571, 99990337, 99999941, 99999931, 99999847, 99999839, 99999827, 99999821, 99999787, 99999773, };
inline i32 get_big_prime() { return big_primes[std::uniform_int_distribution<i32>(0, num_big_primes - 1)(rng)]; }
constexpr i32 mod = i32(1e9) + 9;
constexpr i32 power(i32 n, i32 m) {
i32 res = 1;
while (m) {
if (m & 1) {
res = 1ll * res * n % mod;
}
n = 1ll * n * n % mod;
m >>= 1;
}
return res;
}
constexpr i32 inv_2 = power(2, mod - 2);
i32 main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
i32 n, m;
std::cin >> n >> m;
i32 t = 1ll * (n - 1) * n % mod * inv_2 % mod;
i32 ans = 1;
for (i32 i = 1; i <= n; i++) ans = 1ll * ans * i % mod;
for (i32 i = 1; i <= m; i++) {
ans = 1ll * ans * t % mod;
ans = 1ll * ans * power(i, mod - 2) % mod;
t = (t - 1) % mod;
}
ans = (ans + mod) % mod;
std::cout << ans << std::endl;
std::cerr << "use time: " << 1. * std::clock() / CLOCKS_PER_SEC << std::endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3840kb
input:
3 1
output:
18
result:
ok 1 number(s): "18"
Test #2:
score: 0
Accepted
time: 0ms
memory: 4084kb
input:
4 4
output:
360
result:
ok 1 number(s): "360"
Test #3:
score: 0
Accepted
time: 48ms
memory: 4000kb
input:
39847 348708
output:
983575456
result:
ok 1 number(s): "983575456"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3972kb
input:
1 1
output:
0
result:
ok 1 number(s): "0"
Test #5:
score: 0
Accepted
time: 0ms
memory: 4036kb
input:
3 2
output:
18
result:
ok 1 number(s): "18"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3972kb
input:
3 3
output:
6
result:
ok 1 number(s): "6"
Test #7:
score: 0
Accepted
time: 0ms
memory: 4148kb
input:
3 4
output:
0
result:
ok 1 number(s): "0"
Test #8:
score: 0
Accepted
time: 135ms
memory: 3936kb
input:
3 1000000
output:
0
result:
ok 1 number(s): "0"
Test #9:
score: 0
Accepted
time: 0ms
memory: 4004kb
input:
4 1
output:
144
result:
ok 1 number(s): "144"
Test #10:
score: 0
Accepted
time: 0ms
memory: 3916kb
input:
4 2
output:
360
result:
ok 1 number(s): "360"
Test #11:
score: 0
Accepted
time: 0ms
memory: 3936kb
input:
4 3
output:
480
result:
ok 1 number(s): "480"
Test #12:
score: 0
Accepted
time: 0ms
memory: 3900kb
input:
4 5
output:
144
result:
ok 1 number(s): "144"
Test #13:
score: 0
Accepted
time: 0ms
memory: 4000kb
input:
4 6
output:
24
result:
ok 1 number(s): "24"
Test #14:
score: 0
Accepted
time: 0ms
memory: 3968kb
input:
5 1
output:
1200
result:
ok 1 number(s): "1200"
Test #15:
score: 0
Accepted
time: 0ms
memory: 4136kb
input:
5 2
output:
5400
result:
ok 1 number(s): "5400"
Test #16:
score: 0
Accepted
time: 0ms
memory: 4004kb
input:
5 3
output:
14400
result:
ok 1 number(s): "14400"
Test #17:
score: 0
Accepted
time: 0ms
memory: 3964kb
input:
5 4
output:
25200
result:
ok 1 number(s): "25200"
Test #18:
score: 0
Accepted
time: 0ms
memory: 3960kb
input:
5 5
output:
30240
result:
ok 1 number(s): "30240"
Test #19:
score: 0
Accepted
time: 0ms
memory: 3916kb
input:
5 6
output:
25200
result:
ok 1 number(s): "25200"
Test #20:
score: 0
Accepted
time: 0ms
memory: 3952kb
input:
5 7
output:
14400
result:
ok 1 number(s): "14400"
Test #21:
score: 0
Accepted
time: 0ms
memory: 3960kb
input:
5 8
output:
5400
result:
ok 1 number(s): "5400"
Test #22:
score: 0
Accepted
time: 0ms
memory: 4036kb
input:
5 9
output:
1200
result:
ok 1 number(s): "1200"
Test #23:
score: 0
Accepted
time: 0ms
memory: 4000kb
input:
5 10
output:
120
result:
ok 1 number(s): "120"
Test #24:
score: 0
Accepted
time: 0ms
memory: 4136kb
input:
1000 1
output:
533396879
result:
ok 1 number(s): "533396879"
Test #25:
score: 0
Accepted
time: 0ms
memory: 3968kb
input:
1000 100
output:
199484478
result:
ok 1 number(s): "199484478"
Test #26:
score: 0
Accepted
time: 2ms
memory: 3932kb
input:
1000 10000
output:
656650652
result:
ok 1 number(s): "656650652"
Test #27:
score: 0
Accepted
time: 135ms
memory: 3900kb
input:
1000 1000000
output:
0
result:
ok 1 number(s): "0"
Test #28:
score: 0
Accepted
time: 86ms
memory: 3976kb
input:
535164 619302
output:
721871396
result:
ok 1 number(s): "721871396"
Test #29:
score: 0
Accepted
time: 139ms
memory: 3848kb
input:
1000000 1000000
output:
580712335
result:
ok 1 number(s): "580712335"
Test #30:
score: 0
Accepted
time: 36ms
memory: 3964kb
input:
1000000 234534
output:
546630669
result:
ok 1 number(s): "546630669"
Test #31:
score: 0
Accepted
time: 136ms
memory: 3920kb
input:
234523 1000000
output:
127869098
result:
ok 1 number(s): "127869098"
Test #32:
score: 0
Accepted
time: 2ms
memory: 3844kb
input:
44722 10000
output:
0
result:
ok 1 number(s): "0"