QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#522214#8486. CasinoSTnofarjo#WA 2ms4652kbC++141.3kb2024-08-16 19:42:532024-08-16 19:42:54

Judging History

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

  • [2024-08-16 19:42:54]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:4652kb
  • [2024-08-16 19:42:53]
  • 提交

answer

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

const int maxn = 1e5+3, mod = 1e9+7;
int fac[maxn], ifac[maxn];

int modpow(int a, int b) {
	int ret = 1;
	for (; b; b>>=1) {
		if (b&1) ret = 1LL * ret * a % mod;
		a = 1LL * a * a % mod;
	}
	return ret;
}

void init() {
	fac[0] = 1;
	for (int i=1; i<maxn; i++) fac[i] = 1LL * fac[i-1] * i % mod;
	ifac[maxn-1] = modpow(fac[maxn-1], mod-2);
	for (int i=maxn-1; i>=0; i--) ifac[i-1] = 1LL * ifac[i] * i % mod;
	assert(1LL * fac[5] * ifac[5] % mod == 1);
}

int comb(int a, int b) {
	return 1LL * fac[a] * ifac[b] % mod * ifac[a-b] % mod;
}

void solve() {
	int n;
	cin >> n;
	vector<int> cnt(3, 0);
	for (int i=0; i<n; i++) {
		int a;
		cin >> a;
		cnt[a%3]++;
	}

	// cout << cnt[0] << ' ' << cnt[1] << ' ' << cnt[2] << '\n';

	int ans = 0;
	if (cnt[1] > 0 && cnt[2] + 1 <= cnt[1] && cnt[1] <= cnt[2] + 2) {
		ans = (ans + 1LL * fac[cnt[1]] * fac[cnt[2]] % mod * comb(cnt[1]+cnt[2]+cnt[0]-1, cnt[0])) % mod;
	}
	if (cnt[2] > 0 && cnt[1] + 1 <= cnt[2] && cnt[2] <= cnt[1] + 2) {
		ans = (ans + 1LL * fac[cnt[1]] * fac[cnt[2]] % mod * comb(cnt[1]+cnt[2]+cnt[0]-1, cnt[0])) % mod;
	}

	cout << ans << '\n';
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	init();
	int tcs = 1;
	// cin >> tcs;
	while (tcs--) {
		solve();
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 4360kb

input:

3
100 21 892

output:

4

result:

ok 1 number(s): "4"

Test #2:

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

input:

4
11 19 30 32

output:

6

result:

ok 1 number(s): "6"

Test #3:

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

input:

3
4 298 28

output:

0

result:

ok 1 number(s): "0"

Test #4:

score: -100
Wrong Answer
time: 2ms
memory: 4652kb

input:

5
24 27 38 46 94

output:

12

result:

wrong answer 1st numbers differ - expected: '24', found: '12'