记录编号 323923 评测结果 AAAAAAAAAA
题目名称 [SYOI 2015] Asm_Def排兵布阵 最终得分 100
用户昵称 GravatarFmuckss 是否通过 通过
代码语言 C++ 运行时间 0.030 s
提交时间 2016-10-17 14:50:19 内存使用 4.51 MiB
显示代码纯文本
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long LL;
const int maxn = 1e5 + 10;
const int lcy = 998244353;

int n, top;
int num[maxn];
int inv[maxn * 5], f[maxn * 5];

inline int quick_pow(LL base, int times) {
	LL res = 1;
	while (times) {
		if (times & 1) res = (res * base) % lcy;
		times >>= 1;
		base = (base * base) % lcy;
	}
	return (int)res;
}

#define is_num(x) (x <= '9' and x >= '0')
inline int get_num() {
	char tmp = getchar();
	int res = 0;
	
	while (not is_num(tmp)) tmp = getchar();
	while (    is_num(tmp)) {
		res = (res << 3) + (res << 1) + tmp - '0';
		tmp = getchar();
	}
	
	return res;
}

inline void init() {
	f[0] = f[1] = 1; 
	for (int i = 2; i <= top; i++) f[i] = 1ll * f[i - 1] * i % lcy;
	inv[top] = quick_pow(f[top], lcy - 2);
	for (int i = top - 1; i >= 0; i--) inv[i] = 1ll * inv[i + 1] * (i + 1) % lcy;
}

inline void read() {
	n = get_num();
	for (int i = 1; i <= n; i++) {
		num[i] = get_num();
		top += num[i];
	}
} 

inline void solve() {
	int sum = 0;
	int ans = 1;
	for (int i = 1; i <= n; i++) {
		sum += num[i];
		ans = 1ll * ans * f[sum - 1] % lcy * inv[num[i] - 1] % lcy * inv[sum - num[i]] % lcy;
	}
	printf("%d\n", ans);
}

int main() {
	freopen("asm_formation.in", "r", stdin);
	freopen("asm_formation.out", "w", stdout);
	read();
	init();
	solve();
	return 0;
}