QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#475878#8526. Polygon IIAWRWA 3ms4384kbC++201.9kb2024-07-13 16:55:202024-07-13 16:55:21

Judging History

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

  • [2024-07-13 16:55:21]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:4384kb
  • [2024-07-13 16:55:20]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

#define fir first
#define sec second
#define mpr make_pair

#define vv vector
#define eb emplace_back

#define Fr(i, l, r) for (ll i = l; i <= r; ++i)
#define Rf(i, r, l) for (ll i = r; i >= l; --i)

template<typename T> void Min(T& x, T y) {
	if (y < x) x = y;
}

template<typename T> void Max(T& x, T y) {
	if (y > x) x = y;
}

const long long MD = 1e9 + 7;

ll qpow(ll a, ll b) {
	ll res = 1;
	for (; b; b >>= 1, a = a * a % MD) if (b & 1) res = res * a % MD;
	return res;
}

const long long V = 2000, inv2 = (MD + 1) / 2;

ll n, a[1010], fac[1010], ifac[1010];
ll K[1010], rem[65], cnt[65];
ll ans, dp[65][2010];

ll binom(ll a, ll b) {
	return fac[a] * ifac[b] % MD * ifac[a - b] % MD;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	cin >> n, fac[0] = 1, ifac[0] = 1;
	Fr (i, 1, n) {
		cin >> a[i], ++a[i], ++cnt[a[i]];
		Fr (j, 1, a[i] - 1) ++K[j];
		fac[i] = fac[i - 1] * i % MD;
		ifac[i] = qpow(fac[i], MD - 2);
	}
	Rf (i, 55, 0) rem[i] = rem[i + 1] + K[i];

	Fr (j, 0, n) {
		ll res = 0;
		Fr (i, 0, n) {
			ll val = qpow(max(0ll, j + 1 - i), n) * ifac[n] % MD * binom(n, i) % MD;
			if (i & 1) val = MD - val;
			res = (res + val) % MD;
		}
		dp[0][j] = res;
	}
	Rf (j, n, 1) dp[0][j] = (dp[0][j] - dp[0][j - 1] + MD) % MD;
	Rf (j, V, 0) if (j % 2) dp[0][j] = 0;
	else dp[0][j] = dp[0][j / 2];

	// Fr (i, 0, n) cout << dp[0][i] << '\n';

	Fr (i, 1, 55) {
		ans = (ans + (dp[i - 1][0] + dp[i - 1][1]) * qpow(inv2, rem[i]) % MD * cnt[i]) % MD;
		ll t1 = qpow(inv2, K[i]);
		Fr (j, 0, V) Fr (k, 0, K[i]) {
			ll p = t1 * binom(K[i], k);
			dp[i][j / 2 + k] = (dp[i][j / 2 + k] + dp[i - 1][j] * p) % MD;
		}
		// cout << "ans = " << ans << '\n';
	}
	// cout << dp[2][0] << '\n';
	ans = (1ll - ans + MD) % MD;
	cout << ans << '\n';

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
0 2 0

output:

166666668

result:

ok 1 number(s): "166666668"

Test #2:

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

input:

3
0 0 0

output:

500000004

result:

ok 1 number(s): "500000004"

Test #3:

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

input:

3
5 6 7

output:

208333335

result:

ok 1 number(s): "208333335"

Test #4:

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

input:

3
0 25 50

output:

889268532

result:

ok 1 number(s): "889268532"

Test #5:

score: -100
Wrong Answer
time: 3ms
memory: 4224kb

input:

10
39 11 25 1 12 44 10 46 27 15

output:

976719869

result:

wrong answer 1st numbers differ - expected: '913863330', found: '976719869'