QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#124287 | #2438. Minimum Spanning Trees | Hongzy | AC ✓ | 513ms | 3748kb | C++17 | 3.2kb | 2023-07-14 16:34:53 | 2023-07-14 16:35:03 |
Judging History
answer
#include <bits/stdc++.h>
#define LOG(FMT...) fprintf(stderr, FMT);
#define rep(i, j, k) for(int i = j; i <= k; ++ i)
#define per(i, j, k) for(int i = j; i >= k; -- i)
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
const int N = 50;
const int mod = 1e9 + 7;
int qpow(int a, int b) {
int ans = 1;
for(; b >= 1; b >>= 1, a = (ll)a * a % mod)
if(b & 1) ans = (ll)ans * a % mod;
return ans;
}
namespace ITPL { //O(n^2) Interpolation
vi inter(vi x, vi y) { //in mod
assert(x.size() == y.size());
int n = int(x.size()) - 1; //x, y [0, n]
vi p(1, 1);
rep(i, 0, n) {
p.pb(0);
per(j, i + 1, 0) {
p[j] = ((ll)p[j] * (-x[i]) + (j ? p[j-1] : 0)) % mod;
}
}
vi res(n + 1);
rep(i, 0, n) {
vi q(n + 1);
int z = 1;
rep(j, 0, n) if(j != i)
z = (ll)z * (x[i] - x[j]) % mod;
z = (ll)y[i] * qpow(z, mod-2) % mod;
q[n] = 1;
per(j, n, 1)
q[j-1] = (p[j] + (ll)q[j] * x[i]) % mod;
rep(j, 0, n)
res[j] = (res[j] + (ll)z * q[j]) % mod;
}
rep(i, 0, n)
if(res[i] < 0)
res[i] += mod;
return res;
}
}
int n, k, p[6], sufp[6];
int f[5][N], c[N][N], g[N][N], fac[N], fav[N], e1[N][N], e0[N][N], pw[5 * N];
void upd(int &x, ll y) {
x = (x + y) % mod;
}
int solve(int x0) {
pw[0] = 1;
rep(i, 1, (k-1) * n)
pw[i] = (ll)pw[i-1] * x0 % mod;
f[0][1] = 1;
rep(t, 1, k) {
rep(i, 0, n)
rep(j, 1, n - i) {
int c = i * j;
e0[i][j] = qpow((sufp[t+1] + p[0]) % mod, c);
e1[i][j] = (qpow((p[0] + sufp[t]) % mod, c) - e0[i][j]) % mod;
}
rep(s, 1, n)
rep(i, 0, n-s)
g[s][i] = !i;
rep(d, 1, n) {
f[t][d] = 0;
rep(i, 1, d)
upd(f[t][d], (ll)f[t-1][i] * g[i][d-i] % mod * c[d-1][i-1]);
per(i, n, d) {//g[s][i]
rep(s, 1, n-i) {
int t1 = fac[i], _t3 = 1, t3 = 1;
int tmp = (ll)fav[d] % mod * e1[s][d] % mod * f[t][d] % mod;
rep(k, 1, i / d) {
t1 = (ll)t1 * tmp % mod * _t3 % mod; //d < z
_t3 = (ll)_t3 * e0[d][d] % mod; //pow(e0[d][d], k)
upd(g[s][i], (ll)g[s][i - k*d] * pw[(t-1)*k] % mod * fav[k] % mod * fav[i-k*d] % mod * e0[i - k*d][k*d] % mod * t1);
}
}
}
}
}
return f[k][n];
}
int main() {
rep(i, 0, N-1) {
c[i][0] = 1;
rep(j, 1, i)
c[i][j] = (c[i-1][j-1] + c[i-1][j]) % mod;
}
*fac = 1;
rep(i, 1, N-1) fac[i] = (ll)fac[i-1] * i % mod;
fav[N-1] = qpow(fac[N-1], mod-2);
per(i, N-1, 1) fav[i-1] = (ll)fav[i] * i % mod;
const int i100 = qpow(100, mod-2);
int test;
scanf("%d", &test);
rep(T, 1, test) {
scanf("%d%d", &n, &k);
rep(i, 0, k) scanf("%d", p + i), p[i] = (ll)p[i] * i100 % mod;
sufp[k+1] = 0;
per(i, k, 0) sufp[i] = (sufp[i+1] + p[i]) % mod;
vi x((k - 1) * (n - 1) + 1);
iota(x.begin(), x.end(), 0);
vi y;
for(int x0: x) y.pb(solve(x0));
vi res = ITPL::inter(x, y);
int o = res.size();
for(int z: res) {
printf("%d%c", z, " \n"[!--o]);
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 513ms
memory: 3748kb
input:
200 3 1 50 50 3 2 0 50 50 3 3 25 25 25 25 8 1 41 59 7 3 37 30 7 26 3 3 16 12 18 54 9 2 9 43 48 9 3 3 40 42 15 9 1 29 71 9 2 40 42 18 5 1 76 24 5 1 39 61 9 2 23 38 39 10 4 18 15 34 2 31 7 2 23 28 49 9 4 15 13 25 19 28 7 1 64 36 6 1 50 50 9 1 4 96 4 1 64 36 9 2 24 45 31 9 2 3 61 36 9 1 65 35 8 4 6 1 3...
output:
500000004 500000004 375000003 125000001 406250003 109375001 250000002 265625002 562500004 858129220 40267248 73443306 307645653 13908396 542571454 781149891 223877799 478284083 469782292 483514097 271207900 851118600 686534546 708608005 271088002 536992004 107032001 243224002 763536836 20527108 7248...
result:
ok 200 lines