QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#454835#8526. Polygon IIkarunaWA 11ms3900kbC++202.2kb2024-06-25 15:10:522024-06-25 15:10:52

Judging History

你现在查看的是最新测评结果

  • [2024-06-25 15:10:52]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:3900kb
  • [2024-06-25 15:10:52]
  • 提交

answer

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define ff first
#define ss second
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MOD = 1e9 + 7;
const int SZ = 1020;
const int BW = 60;

struct mint {
	int x;
	mint() : x(0) {}
	mint(int x) : x(x) {}
	mint operator+(const int &ot) const { return x + ot >= MOD ? x + ot - MOD : x + ot; }
	mint operator-(const int &ot) const { return x < ot ? x - ot + MOD : x - ot; }
	mint operator*(const int &ot) const { return 1ll * x * ot % MOD; }
	mint operator+=(int ot) { return *this = *this + ot; }
	mint operator-=(int ot) { return *this = *this - ot; }
	mint operator*=(int ot) { return *this = *this * ot; }
	operator int() { return x; }
};
mint mpow(mint a, ll x) {
	mint r = 1;
	while (x) {
		if (x & 1) r *= a;
		a *= a;
		x /= 2;
	}
	return r;
}

mint init_prb[SZ];
mint fac[SZ], ifac[SZ];

int n, a[SZ], cnt[BW], suf[BW];
mint dp[BW][SZ], ipw[SZ];
int main() {
	cin.tie(0); ios_base::sync_with_stdio(0);

	fac[0] = 1;
	for (int i = 1; i < SZ; i++) fac[i] = fac[i - 1] * i;

	ifac[SZ - 1] = mpow(fac[SZ - 1], MOD - 2);
	for (int i = SZ - 1; i > 0; i--) ifac[i - 1] = ifac[i] * i;

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		cnt[a[i]]++;
	}
	for (int i = BW; i > 0; i--) cnt[i - 1] += cnt[i];
	for (int i = BW; i > 0; i--) suf[i - 1] = suf[i] + cnt[i - 1];

	// probability that x_1 + x_2 + ... + x_n <= k
	for (int k = 0; k <= n; k++) {
		for (int i = 0; i <= k; i++) {
			init_prb[k] += mpow(k - i, n) * ifac[n - i] * ifac[i] * ((i & 1) ? MOD - 1 : 1);
		}
	}
	for (int c = 0; c < n; c++) {
		dp[0][c] = init_prb[c + 1] - init_prb[c];
	}

	mint i2 = mpow(2, MOD - 2);
	ipw[0] = 1;
	for (int i = 1; i < SZ; i++) ipw[i] = ipw[i - 1] * i2;

	for (int s = 1; s < BW; s++) {
		for (int c = 0; c < SZ; c++) {
			for (int x = 0; x <= cnt[s]; x++) {
				dp[s][(c + x) / 2] += dp[s - 1][c] * fac[cnt[s]] * ifac[x] * ifac[cnt[s] - x] * ipw[cnt[s]];
			}
		}
	}

	mint ans = 1;
	for (int i = 0; i < n; i++) {
		ans -= dp[a[i]][0] * ipw[suf[a[i] + 1]];
	}
	cout << ans << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3872kb

input:

3
0 2 0

output:

166666668

result:

ok 1 number(s): "166666668"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3872kb

input:

3
0 0 0

output:

500000004

result:

ok 1 number(s): "500000004"

Test #3:

score: 0
Accepted
time: 1ms
memory: 3896kb

input:

3
5 6 7

output:

208333335

result:

ok 1 number(s): "208333335"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3896kb

input:

3
0 25 50

output:

889268532

result:

ok 1 number(s): "889268532"

Test #5:

score: 0
Accepted
time: 2ms
memory: 3900kb

input:

10
39 11 25 1 12 44 10 46 27 15

output:

913863330

result:

ok 1 number(s): "913863330"

Test #6:

score: -100
Wrong Answer
time: 11ms
memory: 3828kb

input:

57
43 22 3 16 7 5 24 32 25 16 41 28 24 30 28 10 32 48 41 43 34 37 48 34 3 9 21 41 49 25 2 0 36 45 34 33 45 9 42 29 43 9 38 34 44 33 44 6 46 39 22 36 40 37 19 34 3

output:

897660750

result:

wrong answer 1st numbers differ - expected: '400729664', found: '897660750'