QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#107471 | #5749. Directed Vertex Cacti | zhoukangyang | AC ✓ | 11ms | 3500kb | C++17 | 7.5kb | 2023-05-21 16:39:55 | 2023-05-21 16:39:59 |
Judging History
answer
#include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); ++i)
#define R(i, j, k) for(int i = (j); i >= (k); --i)
#define ll long long
#define vi vector < int >
#define sz(a) ((int) (a).size())
#define ll long long
#define ull unsigned long long
#define me(a, x) memset(a, x, sizeof(a))
#define eb emplace_back
#define uint unsigned int
using namespace std;
const int mod = 1e9 + 9;
int qpow(int x, int y = mod - 2) {
int ret = 1;
for(; y; x = (ll) x * x % mod, y >>= 1) if(y & 1) ret = (ll) ret * x % mod;
return ret;
}
int main() {
int n, m;
cin >> n >> m;
int W = (ll) n * (n - 1) / 2 % mod;
int ls = 1, rs = 1;
L(i, 1, m) ls = (ll) ls * (W - i + 1) % mod, rs = (ll) rs * i % mod;
int ans = (ll) ls * qpow(rs) % mod;
L(i, 1, n) ans = (ll) ans * i % mod;
cout << ans << '\n';
}
/*
const int mod = 998244353, _G = 3, N = (1 << 21), inv2 = (mod + 1) / 2;
#define add(a, b) (a + b >= mod ? a + b - mod : a + b)
#define dec(a, b) (a < b ? a - b + mod : a - b)
int qpow(int x, int y = mod - 2) {
int res = 1;
for(; y; x = (ll) x * x % mod, y >>= 1) if(y & 1) res = (ll) res * x % mod;
return res;
}
int fac[N], ifac[N], inv[N];
void init(int x) {
fac[0] = ifac[0] = inv[1] = 1;
L(i, 2, x) inv[i] = (ll) inv[mod % i] * (mod - mod / i) % mod;
L(i, 1, x) fac[i] = (ll) fac[i - 1] * i % mod, ifac[i] = (ll) ifac[i - 1] * inv[i] % mod;
}
int C(int x, int y) {
return y < 0 || x < y ? 0 : (ll) fac[x] * ifac[y] % mod * ifac[x - y] % mod;
}
int rt[N], Lim;
void Pinit(int x) {
for(Lim = 1; Lim <= x; Lim <<= 1) ;
for(int i = 1; i < Lim; i <<= 1) {
int sG = qpow (_G, (mod - 1) / (i << 1));
rt[i] = 1;
L(j, i + 1, i * 2 - 1) rt[j] = (ll) rt[j - 1] * sG % mod;
}
}
struct poly {
vector<int> a;
int size() { return sz(a); }
int & operator [] (int x) { return a[x]; }
int v(int x) { return x < 0 || x >= sz(a) ? 0 : a[x]; }
void clear() { vector<int> ().swap(a); }
void rs(int x = 0) { a.resize(x); }
poly (int n = 0) { rs(n); }
poly (vector<int> o) { a = o; }
poly (const poly &o) { a = o.a; }
poly Rs(int x = 0) { vi res = a; res.resize(x); return res; }
inline void dif() {
int n = sz(a);
for (int l = n >> 1; l >= 1; l >>= 1)
for(int j = 0; j < n; j += l << 1)
for(int k = 0, *w = rt + l; k < l; k++, w++) {
int x = a[j + k], y = a[j + k + l];
a[j + k] = add(x, y);
a[j + k + l] = (ll) * w * dec(x, y) % mod;
}
}
void dit () {
int n = sz(a);
for(int i = 2; i <= n; i <<= 1)
for(int j = 0, l = (i >> 1); j < n; j += i)
for(int k = 0, *w = rt + l; k < l; k++, w++) {
int pa = a[j + k], pb = (ll) a[j + k + l] * *w % mod;
a[j + k] = add(pa, pb), a[j + k + l] = dec(pa, pb);
}
reverse(a.begin() + 1, a.end());
for(int i = 0, iv = qpow(n); i < n; i++) a[i] = (ll) a[i] * iv % mod;
}
friend poly operator * (poly aa, poly bb) {
if(!sz(aa) || !sz(bb)) return {};
int lim, all = sz(aa) + sz(bb) - 1;
for(lim = 1; lim < all; lim <<= 1);
aa.rs(lim), bb.rs(lim), aa.dif(), bb.dif();
L(i, 0, lim - 1) aa[i] = (ll) aa[i] * bb[i] % mod;
aa.dit(), aa.a.resize(all);
return aa;
}
poly Inv() {
poly res, f, g;
res.rs(1), res[0] = qpow(a[0]);
for(int m = 1, pn; m < sz(a); m <<= 1) {
pn = m << 1, f = res, g.rs(pn), f.rs(pn);
for(int i = 0; i < pn; i++) g[i] = (*this).v(i);
f.dif(), g.dif();
for(int i = 0; i < pn; i++) g[i] = (ll) f[i] * g[i] % mod;
g.dit();
for(int i = 0; i < m; i++) g[i] = 0;
g.dif();
for(int i = 0; i < pn; i++) g[i] = (ll) f[i] * g[i] % mod;
g.dit(), res.rs(pn);
for(int i = m; i < min(pn, sz(a)); i++) res[i] = (mod - g[i]) % mod;
}
return res.rs(sz(a)), res;
}
poly Shift (int x) {
poly zm (sz(a) + x);
L(i, max(-x, 0), sz(a) - 1) zm[i + x] = a[i];
return zm;
}
friend poly operator * (poly aa, int bb) {
poly res(sz(aa));
L(i, 0, sz(aa) - 1) res[i] = (ll) aa[i] * bb % mod;
return res;
}
friend poly operator + (poly aa, poly bb) {
vector<int> res(max(sz(aa), sz(bb)));
L(i, 0, sz(res) - 1) res[i] = add(aa.v(i), bb.v(i));
return poly(res);
}
friend poly operator - (poly aa, poly bb) {
vector<int> res(max(sz(aa), sz(bb)));
L(i, 0, sz(res) - 1) res[i] = dec(aa.v(i), bb.v(i));
return poly(res);
}
poly & operator += (poly o) {
rs(max(sz(a), sz(o)));
L(i, 0, sz(a) - 1) (a[i] += o.v(i)) %= mod;
return (*this);
}
poly & operator -= (poly o) {
rs(max(sz(a), sz(o)));
L(i, 0, sz(a) - 1) (a[i] += mod - o.v(i)) %= mod;
return (*this);
}
poly & operator *= (poly o) {
return (*this) = (*this) * o;
}
poly Integ() {
if(!sz(a)) return poly();
poly res(sz(a) + 1);
L(i, 1, sz(a)) res[i] = (ll) a[i - 1] * inv[i] % mod;
return res;
}
poly Deriv() {
if(!sz(a)) return poly();
poly res(sz(a) - 1);
L(i, 1, sz(a) - 1) res[i - 1] = (ll) a[i] * i % mod;
return res;
}
poly Ln() {
poly g = ((*this).Inv() * (*this).Deriv()).Integ();
return g.rs(sz(a)), g;
}
poly Exp() {
poly res(1), f;
res[0] = 1;
for(int m = 1, pn; m < sz(a); m <<= 1) {
pn = min(m << 1, sz(a)), f.rs(pn), res.rs(pn);
for(int i = 0; i < pn; i++) f[i] = (*this).v(i);
f -= res.Ln(), (f[0] += 1) %= mod, res *= f, res.rs(pn);
}
return res.rs(sz(a)), res;
}
poly pow(int x, int rx = -1) { // x : the power % mod; rx : the power % (mod - 1)
if(rx == -1) rx = x;
int cnt = 0;
while (a[cnt] == 0 && cnt < sz(a)) cnt += 1;
poly res = (*this);
L(i, cnt, sz(a) - 1) res[i - cnt] = res[i];
L(i, sz(a) - cnt, sz(a) - 1) res[i] = 0;
int c = res[0], w = qpow (res[0]);
L(i, 0, sz(res) - 1) res[i] = (ll) res[i] * w % mod;
res = res.Ln();
L(i, 0, sz(res) - 1) res[i] = (ll) res[i] * x % mod;
res = res.Exp();
c = qpow (c, rx);
L(i, 0, sz(res) - 1) res[i] = (ll) res[i] * c % mod;
if((ll) cnt * x > sz(a)) L(i, 0, sz(a) - 1) res[i] = 0;
else if(cnt) {
R(i, sz(a) - cnt * x - 1, 0) res[i + cnt * x] = res[i];
L(i, 0, cnt * x - 1) res[i] = 0;
}
return res;
}
poly sqrt(int rt = 1) {
poly res(1), f;
res[0] = rt;
for(int m = 1, pn; m < sz(a); m <<= 1) {
pn = min(m << 1, sz(a)), f.rs(pn);
for(int i = 0; i < pn; i++) f[i] = (*this).v(i);
f += res * res, f.rs(pn), res.rs(pn), res = f * res.Inv(), res.rs(pn);
for(int i = 0; i < pn; i++) res[i] = (ll) res[i] * inv2 % mod;
}
return res;
}
void Rev() {
reverse(a.begin(), a.end());
}
} ;
int n, m, f[N], g[N];
int dp[114][10000];
int sgn(int x) {
return (x & 1) ? mod - 1 : 1;
}
int main() {
ios :: sync_with_stdio(false);
cin.tie(0); cout.tie(0);
init(N - 7), Pinit(N / 2);
cin >> n;
L(i, 1, n) {
// f[i] = (ll) inv[i] * 2 % mod;
// if(i <= 2) f[i] = inv[i];
f[i] = inv[i];
}
poly g(n + 1), f(n + 1);
L(i, 1, n) {
f[i] = ::f[i];
}
L(k, 1, n) {
int w = (ll) sgn(k - 1) * ifac[k] % mod;
g += f.pow(k) * w;
}
// L(i, 1, n)
// g[i] = mod - f[i];
// g = vi{} - g.Exp();
g[0] = 0;
dp[0][0] = 1;
L(i, 0, n) {
L(j, 0, n * (n - 1) / 2) if(dp[i][j]) {
L(k, 1, n - i) {
(dp[i + k][j + i * k] += (ll) dp[i][j] * g[k] % mod) %= mod;
}
}
}
L(m, 1, n * (n - 1) / 2) {
int s = 0;
L(i, 1, n * (n - 1) / 2) {
(s += (ll) dp[n][i] * C(i, m) % mod) %= mod;
}
int cm = C(n, 2);
int prd = 1;
L(i, 1, m) prd = (ll) prd * (cm - i + 1) % mod * inv[i] % mod;
cout << 1. * ((ll)s*fac[n]%mod) / prd << '\n';
}
// L(i, 0, n)
// cout << mod - (ll) g[i] * fac[i] % mod << ' ' <<
// (ll) i * (i + 9) / 2 - 10 << endl;
return 0;
}
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3308kb
input:
3 1
output:
18
result:
ok 1 number(s): "18"
Test #2:
score: 0
Accepted
time: 2ms
memory: 3308kb
input:
4 4
output:
360
result:
ok 1 number(s): "360"
Test #3:
score: 0
Accepted
time: 4ms
memory: 3268kb
input:
39847 348708
output:
983575456
result:
ok 1 number(s): "983575456"
Test #4:
score: 0
Accepted
time: 2ms
memory: 3392kb
input:
1 1
output:
0
result:
ok 1 number(s): "0"
Test #5:
score: 0
Accepted
time: 3ms
memory: 3388kb
input:
3 2
output:
18
result:
ok 1 number(s): "18"
Test #6:
score: 0
Accepted
time: 2ms
memory: 3336kb
input:
3 3
output:
6
result:
ok 1 number(s): "6"
Test #7:
score: 0
Accepted
time: 1ms
memory: 3332kb
input:
3 4
output:
0
result:
ok 1 number(s): "0"
Test #8:
score: 0
Accepted
time: 4ms
memory: 3336kb
input:
3 1000000
output:
0
result:
ok 1 number(s): "0"
Test #9:
score: 0
Accepted
time: 2ms
memory: 3272kb
input:
4 1
output:
144
result:
ok 1 number(s): "144"
Test #10:
score: 0
Accepted
time: 2ms
memory: 3324kb
input:
4 2
output:
360
result:
ok 1 number(s): "360"
Test #11:
score: 0
Accepted
time: 0ms
memory: 3448kb
input:
4 3
output:
480
result:
ok 1 number(s): "480"
Test #12:
score: 0
Accepted
time: 2ms
memory: 3308kb
input:
4 5
output:
144
result:
ok 1 number(s): "144"
Test #13:
score: 0
Accepted
time: 1ms
memory: 3332kb
input:
4 6
output:
24
result:
ok 1 number(s): "24"
Test #14:
score: 0
Accepted
time: 2ms
memory: 3268kb
input:
5 1
output:
1200
result:
ok 1 number(s): "1200"
Test #15:
score: 0
Accepted
time: 0ms
memory: 3392kb
input:
5 2
output:
5400
result:
ok 1 number(s): "5400"
Test #16:
score: 0
Accepted
time: 2ms
memory: 3336kb
input:
5 3
output:
14400
result:
ok 1 number(s): "14400"
Test #17:
score: 0
Accepted
time: 0ms
memory: 3244kb
input:
5 4
output:
25200
result:
ok 1 number(s): "25200"
Test #18:
score: 0
Accepted
time: 1ms
memory: 3492kb
input:
5 5
output:
30240
result:
ok 1 number(s): "30240"
Test #19:
score: 0
Accepted
time: 2ms
memory: 3400kb
input:
5 6
output:
25200
result:
ok 1 number(s): "25200"
Test #20:
score: 0
Accepted
time: 2ms
memory: 3324kb
input:
5 7
output:
14400
result:
ok 1 number(s): "14400"
Test #21:
score: 0
Accepted
time: 1ms
memory: 3392kb
input:
5 8
output:
5400
result:
ok 1 number(s): "5400"
Test #22:
score: 0
Accepted
time: 1ms
memory: 3312kb
input:
5 9
output:
1200
result:
ok 1 number(s): "1200"
Test #23:
score: 0
Accepted
time: 2ms
memory: 3388kb
input:
5 10
output:
120
result:
ok 1 number(s): "120"
Test #24:
score: 0
Accepted
time: 0ms
memory: 3452kb
input:
1000 1
output:
533396879
result:
ok 1 number(s): "533396879"
Test #25:
score: 0
Accepted
time: 2ms
memory: 3500kb
input:
1000 100
output:
199484478
result:
ok 1 number(s): "199484478"
Test #26:
score: 0
Accepted
time: 2ms
memory: 3320kb
input:
1000 10000
output:
656650652
result:
ok 1 number(s): "656650652"
Test #27:
score: 0
Accepted
time: 6ms
memory: 3500kb
input:
1000 1000000
output:
0
result:
ok 1 number(s): "0"
Test #28:
score: 0
Accepted
time: 7ms
memory: 3492kb
input:
535164 619302
output:
721871396
result:
ok 1 number(s): "721871396"
Test #29:
score: 0
Accepted
time: 11ms
memory: 3324kb
input:
1000000 1000000
output:
580712335
result:
ok 1 number(s): "580712335"
Test #30:
score: 0
Accepted
time: 7ms
memory: 3456kb
input:
1000000 234534
output:
546630669
result:
ok 1 number(s): "546630669"
Test #31:
score: 0
Accepted
time: 7ms
memory: 3452kb
input:
234523 1000000
output:
127869098
result:
ok 1 number(s): "127869098"
Test #32:
score: 0
Accepted
time: 2ms
memory: 3308kb
input:
44722 10000
output:
0
result:
ok 1 number(s): "0"