QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#555800#8526. Polygon IITrueFalseWA 1ms3844kbC++142.6kb2024-09-10 10:05:502024-09-10 10:05:51

Judging History

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

  • [2024-09-10 10:05:51]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3844kb
  • [2024-09-10 10:05:50]
  • 提交

answer

/**
 * @author TrueFalse
 * @date 2024.9.10
 * @version 1.0
 */

#include <bits/stdc++.h>
using namespace std;

using ci = const int;

using u32 = uint32_t;
using i64 =  int64_t;
using u64 = uint64_t;

template<class T> inline void Max(T &x, const T &y) { if (x < y) x = y; }
template<class T> inline void Min(T &x, const T &y) { if (y < x) x = y; }

const int N = 1005;
const int mod = 1e9 + 7;
const int inv2 = (mod + 1) / 2;

struct Module {
	int v;

	Module() {}
	Module(ci &_v) : v(_v) {}

	static constexpr int dil(int x) { return x >> 31 ? x + mod : x; }

	Module operator-() const { return v ? mod - v : v; }

#define _(s) friend Module operator s(const Module &x, const Module &y)
	_(+) { return Module(dil(x.v + y.v - mod)); }
	_(-) { return Module(dil(x.v - y.v)); }
	_(*) { return Module(static_cast<u64>(x.v) * static_cast<u64>(y.v) % mod); }
#undef _

#define _(s, t) void operator s(const Module &o) { *this = *this t o; }
	_(+=, +) _(-=, -) _(*=, *)
#undef _
};

template<class T> T qpow(T x, int y) {
	T z(1);
	do {
		if (y & 1) z *= x;
	} while (x *= x, y >>= 1);
	return z;
}

/**
 * 因为这个进位十分地构式,所以要向前平移 n 个单位。
 */

int n, a[N], s[55];

Module C[N][N], p[N];

void initC() {
	C[0][0] = C[1][0] = C[1][1] = 1;
	for (int i = 2; i <= n; ++i)
		for (int j = 0; j <= i; ++j)
			C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
}

Module dp[55][N], f[55][N];

int main() {
#ifndef ONLINE_JUDGE
	freopen(".in", "r", stdin);
	freopen(".out", "w", stdout);
#endif

	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> a[i], ++s[a[i]];
	for (int i = 50; i; --i) s[i - 1] += s[i];
	initC();

	Module inv(1);
	for (int i = 1; i <= n; ++i) inv *= i;
	inv = qpow(inv, mod - 2);
	for (int i = 0; i <= n; ++i) {
		Module op(1);
		for (int j = 0; j <= i; ++j) {
			p[i] += op * C[n][j] * qpow(i - j, n);
			op = -op;
		}
		p[i] *= inv;
	}
	for (int i = n; i; --i) p[i] -= p[i - 1];
	for (int i = 0; i <= n; ++i) dp[0][1000 - i + 1] = p[i];
	for (int i = 0; i <= 50; ++i) {
		if (!s[i]) break;
		for (int j = 0; j <= 1002; ++j) {
			inv = qpow(Module(inv2), s[i]);
			Module n1;
			for (int k = 0; k < s[i]; ++k) {
				n1 = dp[i][j] * C[s[i] - 1][k] * inv;
				dp[i + 1][(j + 1000 - k + 0) >> 1] += n1;
				dp[i + 1][(j + 1000 - k + 1) >> 1] += n1;
			}
		}
	}

	Module ans(0);
	for (int i = 1; i <= n; ++i) {
		for (int j = 1000; j <= 1002; ++j) {
			int n1(0);
			for (int k = a[i] + 1; k <= 50; ++k) n1 += s[k];
			ans += dp[a[i] + 1][j] * qpow(Module(inv2), n1);
		}
	}
	cout << (1 - ans).v;

	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3648kb

input:

3
0 2 0

output:

166666668

result:

ok 1 number(s): "166666668"

Test #2:

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

input:

3
0 0 0

output:

500000004

result:

ok 1 number(s): "500000004"

Test #3:

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

input:

3
5 6 7

output:

208333335

result:

ok 1 number(s): "208333335"

Test #4:

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

input:

3
0 25 50

output:

889268532

result:

ok 1 number(s): "889268532"

Test #5:

score: -100
Wrong Answer
time: 1ms
memory: 3844kb

input:

10
39 11 25 1 12 44 10 46 27 15

output:

479945000

result:

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