QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#53541 | #2307. 树 | not_so_organic | 100 ✓ | 227ms | 35692kb | C++11 | 1.5kb | 2022-10-05 13:17:37 | 2022-10-05 13:17:38 |
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())
using namespace std;
const int N = 1 << 12;
int mod;
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) (mod - mod / i) * inv[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 x < y || y < 0 ? 0 : (ll) fac[x] * ifac[y] % mod * ifac[x - y] % mod;
}
int n, k, dp[N][N], pe[N][N], W[N][N], F[N], Z[N][N];
int main () {
ios :: sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n >> k >> mod;
init (n);
L(i, 1, n) {
L(j, 1, n / i) F[j] = W[i][j] = qpow (ifac[j], (ll) i * k % (mod - 1));
L(j, 1, n / i) L(k, 1, j - 1) (W[i][j] += mod - (ll) W[i][k] * k % mod * inv[j] % mod * F[j - k] % mod) %= mod;
}
L(i, 1, n) Z[i][0] = 1;
L(i, 1, n) {
L(j, 1, n / i) {
L(k, 1, i - 1)
(Z[j][i - 1] += (ll) Z[j][i - 1 - k] * pe[j][k] % mod * k % mod * inv[i - 1] % mod) %= mod;
dp[i][j] = (ll) Z[j][i - 1] * qpow (inv[i], (ll) j * k % (mod - 1)) % mod;
}
L(j, 1, n / i)
L(k, 1, n / (i * j))
(pe[j][i * k] += (ll) W[j][k] * dp[i][j * k] % mod) %= mod;
}
cout << (ll) dp[n][1] * qpow (n, k) % mod << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 10
Accepted
time: 3ms
memory: 3800kb
input:
5 2 736853057
output:
621719767
result:
ok single line: '621719767'
Test #2:
score: 10
Accepted
time: 2ms
memory: 3924kb
input:
10 2 302939617
output:
145443067
result:
ok single line: '145443067'
Test #3:
score: 10
Accepted
time: 1ms
memory: 3980kb
input:
20 2 662072321
output:
267646252
result:
ok single line: '267646252'
Test #4:
score: 10
Accepted
time: 3ms
memory: 4352kb
input:
50 2 806053187
output:
155980816
result:
ok single line: '155980816'
Test #5:
score: 10
Accepted
time: 3ms
memory: 4476kb
input:
49 2 953748661
output:
691695523
result:
ok single line: '691695523'
Test #6:
score: 10
Accepted
time: 4ms
memory: 4348kb
input:
50 286072115 443534951
output:
284050905
result:
ok single line: '284050905'
Test #7:
score: 10
Accepted
time: 3ms
memory: 6688kb
input:
200 903188218 276454751
output:
40047627
result:
ok single line: '40047627'
Test #8:
score: 10
Accepted
time: 24ms
memory: 11660kb
input:
500 668948355 993729403
output:
636747279
result:
ok single line: '636747279'
Test #9:
score: 10
Accepted
time: 64ms
memory: 19580kb
input:
1000 980382612 268177673
output:
158308282
result:
ok single line: '158308282'
Test #10:
score: 10
Accepted
time: 227ms
memory: 35692kb
input:
2000 178570326 857509859
output:
372489332
result:
ok single line: '372489332'
Extra Test:
score: 0
Extra Test Passed