25pts,和测试点答案一模一样,但是就是WA
查看原帖
25pts,和测试点答案一模一样,但是就是WA
593958
sun_qy楼主2024/1/3 16:18
#include <bits/stdc++.h>
using namespace std;
struct node {
	int a[22500];
	node() {
		memset(a, 0, sizeof(a));
	}
	node(unsigned long long x) {
		int i = 1;
		while(x) {
			a[i ++] = x % 10;
			x /= 10;
		}
		a[0] = -- i;
	}
	void input() {
		string s;
		cin >> s;
		a[0] = s.size();
		for(int i = 1; i <= a[0]; i ++)
			a[i] = s[a[0] - i] - '0';
	}
	bool zero() {
		return a[0] == 1 && a[1] == 0;
	}
	void print() {
		if(zero()) {
			printf("0\n");
			return;
		}
		int tmp = 0;
		for(int i = a[0]; i >= 1; i --) {
			if(a[i] || tmp) {
				printf("%d", a[i]);
				tmp = 1;
			}
		}
		printf("\n");
	}
};
inline node operator + (node x, node y) {
	node res;
	res.a[0] = max(x.a[0], y.a[0]);
	for(int i = 1; i <= res.a[0]; i ++) {
		res.a[i] += x.a[i] + y.a[i];
		if(res.a[i] >= 10) res.a[i] -= 10, res.a[i + 1] ++;
	}
	if(res.a[res.a[0] + 1]) res.a[0] ++;
	return res;
}
inline node operator * (node x, node y) {
	int lx = x.a[0], ly = y.a[0];
	node res;
	if(x.zero()) return x;
	if(y.zero()) return y;
	res.a[0] = lx + ly;
	for(int i = 1; i <= lx; i ++) {
		for(int j = 1; j <= ly; j ++) {
			res.a[i + j - 1] += ((x.a[i] * y.a[j]) % 10);
			res.a[i + j] += ((x.a[i] * y.a[j]) / 10);
			res.a[i + j] += res.a[i + j - 1] / 10;
			res.a[i + j - 1] %= 10;
		}
	}
	if(res.a[lx + ly]) res.a[0] ++;
	return res;
}
inline node operator - (node x, node y) {
	node res;
	if(y.zero()) return x;
	res.a[0] = max(x.a[0], y.a[0]);
	for(int i = 1; i <= res.a[0]; i ++) {
		res.a[i] += x.a[i] - y.a[i];
		if(res.a[i] < 0) x.a[i + 1] --, res.a[i] += 10;
	}
	if(res.a[res.a[0]] == 0) res.a[0] --;
	if(res.a[0] == 0) res.a[0] = 1, res.a[1] = 0;
	return res;
}
node fac(node x) {
	node res = 1;
	for(; !x.zero(); x = x - 1) {
		res = res * x;
	}
	return res;
}
int main() {
	node t, res;
	t.input();
	while(!t.zero()) {
		res = res + fac(t);
		t = t - 1;
	}
	res.print();
	return 0;
}

注:其它ojAC了,数据范围比这个还大,对拍没有任何问题

2024/1/3 16:18
加载中...