QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#444427 | #8526. Polygon II | ucup-team3564# | WA | 1ms | 4132kb | C++14 | 1.8kb | 2024-06-15 19:07:04 | 2024-06-15 19:07:05 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
int norm(int x) { return x >= mod ? x - mod : x; }
int reduce(int x) { return x < 0 ? x + mod : x; }
int neg(int x) { return x ? mod - x : 0; }
int quo2(int x) { return (x + (x & 1 ? mod : 0)) >> 1; }
void add(int &x, int y) { x += y, x = x >= mod ? x - mod : x; }
void sub(int &x, int y) { x -= y, x = x < 0 ? x + mod : x; }
void fam(int &x, int y, int z) { x = (x + (ll)y * z) % mod; }
int mpow(int a, int b) {
int ret = 1;
for (; b; b >>= 1) {
if (b & 1) ret = (ll)ret * a % mod;
a = (ll)a * a % mod;
}
return ret;
}
const int N = 1e3;
const int V = 50;
int n;
int fac[N + 5], ifac[N + 5], pw[N + 5], g[N + 5];
int a[N + 5], inv = 1, cnt[N + 5];
int f[V + 5][N + 5];
int ans;
int main() {
scanf("%d", &n), fac[0] = 1;
for (int i = 1; i <= n; ++i) fac[i] = (ll)fac[i - 1] * i % mod;
ifac[n] = mpow(fac[n], mod - 2);
for (int i = n; i; --i) ifac[i - 1] = (ll)ifac[i] * i % mod;
for (int i = 0; i <= n; ++i) pw[i] = mpow(i, n);
for (int i = 1; i <= n; ++i)
for (int j = 0; j <= i; ++j)
g[i] = (g[i] + (ll)(j & 1 ? mod - ifac[j] : ifac[j]) * ifac[n - j] * pw[i - j]) % mod;
for (int i = 1; i <= n; ++i) scanf("%d", a + i), ++cnt[a[i]], inv = (ll)inv * mpow(2, mod - 1 - a[i]) % mod;
for (int i = V; i; --i) cnt[i - 1] += cnt[i];
for (int i = 0; i < n; ++i) f[0][i] = reduce(g[i + 1] - g[i]);
for (int i = 0; i < V; ++i)
for (int j = 0; j <= n; ++j)
if (f[i][j])
for (int k = 0; k <= cnt[i + 1]; ++k)
fam(f[i + 1][(j + k) >> 1], f[i][j], (ll)fac[cnt[i + 1]] * ifac[k] % mod * ifac[cnt[i + 1] - k] % mod);
for (int i = 1; i <= n; ++i) add(ans, f[a[i]][0]);
ans = (1 + (ll)(mod - ans) * inv) % mod, printf("%d\n", ans);
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 4132kb
input:
3 0 2 0
output:
166666668
result:
ok 1 number(s): "166666668"
Test #2:
score: 0
Accepted
time: 1ms
memory: 4132kb
input:
3 0 0 0
output:
500000004
result:
ok 1 number(s): "500000004"
Test #3:
score: 0
Accepted
time: 0ms
memory: 4112kb
input:
3 5 6 7
output:
208333335
result:
ok 1 number(s): "208333335"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3992kb
input:
3 0 25 50
output:
889268532
result:
ok 1 number(s): "889268532"
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 4128kb
input:
10 39 11 25 1 12 44 10 46 27 15
output:
665566068
result:
wrong answer 1st numbers differ - expected: '913863330', found: '665566068'