QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#446413#8526. Polygon IIucup-team266WA 1ms4244kbC++143.0kb2024-06-17 10:00:562024-06-17 10:00:57

Judging History

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

  • [2024-06-17 10:00:57]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4244kb
  • [2024-06-17 10:00:56]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef array<int, 3> ai3;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const int Mod = 1e9 + 7;
inline int sign(int a){ return (a&1) ? (Mod-1) : 1; }
inline void uadd(int &a, int b){ a += b-Mod; a += (a>>31) & Mod; }
inline void usub(int &a, int b){ a -= b, a += (a>>31) & Mod; }
inline void umul(int &a, int b){ a = (int)(1ll * a * b % Mod); }
inline int add(int a, int b){ a += b-Mod; a += (a>>31) & Mod; return a; }
inline int sub(int a, int b){ a -= b, a += (a>>31) & Mod; return a; }
inline int mul(int a, int b){ a = (int)(1ll * a * b % Mod); return a; }
int qpow(int b, ll p){ int ret = 1; while(p){ if(p&1) umul(ret, b); umul(b, b), p >>= 1; } return ret; }
const int fN = 10010;
int fact[fN], invfact[fN], pw2[fN], invpw2[fN], inv[fN];
void initfact(int n){
	pw2[0] = 1; for(int i = 1; i <= n; ++i) pw2[i] = mul(pw2[i-1], 2);
	invpw2[0] = 1; for(int i = 1; i <= n; ++i) invpw2[i] = mul(invpw2[i-1], (Mod+1) / 2);
	fact[0] = 1; for(int i = 1; i <= n; ++i) fact[i] = mul(fact[i-1], i);
	invfact[n] = qpow(fact[n], Mod-2); for(int i = n; i > 0; --i) invfact[i-1] = mul(invfact[i], i);
	for(int i = 1; i <= n; ++i) inv[i] = mul(invfact[i], fact[i-1]);
}
int binom(int n, int m){ return (m < 0 || m > n) ? 0 : mul(fact[n], mul(invfact[m], invfact[n-m])); }
const double pi = acos(-1);
template<typename T> inline void chmax(T &_a, T _b){ (_a<_b) ? (_a=_b) : 0; }
template<typename T> inline void chmin(T &_a, T _b){ (_b<_a) ? (_a=_b) : 0; }
mt19937_64 rng(58);
inline int myrand(int l, int r){ return (int)(rng() % (r-l+1)) + l; }

int n, a[1010];
int cnt[55], suf[55];

int pr[1010];

int dp[55][2020];
int dfs(int i, int d){
	//cout << "dfs " << i << " " << d << endl;
	if(d >= 2*n + 1) return 1;
	int &ret = dp[i][d];
	if(ret >= 0) return ret;
	if(!i) return ret = (d >= n ? 1 : pr[d + 1]);
	ret = 0;
	for(int x = 0; x <= suf[i]; ++x){
		int coef = mul(binom(suf[i], x), invpw2[suf[i] + 1]);
		if(2*d - x >= 0) uadd(ret, mul(dfs(i - 1, 2*d - x), coef));
		if(2*d + 1 - x >= 0) uadd(ret, mul(dfs(i - 1, 2*d + 1 - x), coef));
	}
	return ret;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> n;

	initfact(10000);
	for(int i = 1; i <= n; ++i){
		for(int j = 0; j <= i; ++j){
			uadd(pr[i], mul(binom(n, j), mul(sign(j), mul(qpow(i - j, n), invfact[n]))));
		}
	}
	//for(int j = 1; j <= n; ++j) cout << pr[j] << " ";
	//cout << "\n";

	rep(i, n) cin >> a[i], ++cnt[a[i]];
	for(int i = 50; i >= 0; --i) suf[i] += suf[i + 1];
	rep(i, 51) --suf[i];
	memset(dp, -1, sizeof(dp));

	int ans = 1;
	rep(i, 51){
		--cnt[i];
		int ret = dfs(i, 0);
		++cnt[i];
		usub(ans, mul(ret, cnt[i]));
	}

	int tmp = 1;
	rep(i, n) umul(tmp, invpw2[a[i]]);
	cout << mul(tmp, ans) << "\n";

	return 0;
}

詳細信息

Test #1:

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

input:

3
0 2 0

output:

166666668

result:

ok 1 number(s): "166666668"

Test #2:

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

input:

3
0 0 0

output:

500000004

result:

ok 1 number(s): "500000004"

Test #3:

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

input:

3
5 6 7

output:

871372229

result:

wrong answer 1st numbers differ - expected: '208333335', found: '871372229'