求助,这段代码为什么会CE
  • 板块灌水区
  • 楼主chrispang
  • 当前回复2
  • 已保存回复2
  • 发布时间2024/8/18 17:06
  • 上次更新2024/8/18 20:05:45
查看原帖
求助,这段代码为什么会CE
786127
chrispang楼主2024/8/18 17:06

rt

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

int read() {
	int x = 0, f = 1;
	char ch = getchar();
	while(ch < '0' || ch > '9') f *= (ch == '-' ? -1 : 1), ch = getchar();
	while(ch >= 48 && ch <= 57) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	return x * f;
}

void write(int x) {
	if(x < 0) putchar('-'), x = -x;
	if(x > 9) write(x / 10);
	putchar(x % 10 ^ 48);
}

int n, p, sum = 0, maxx = -0x3f3f3f3f, f[1000010], a[1000010], res[1000010];
signed main() {
	n = read(), p = read();
	for (int i = 1; i <= n; i++)
		a[i] = read();
	for (int i = 1; i <= n; i++) {
		if(sum < 0) sum = 0;
		sum += a[i];
		maxx = max(maxx, sum);
		f[i] = maxx;
	}
	res[1] = f[1];
	maxx = res[1] + f[1];
	int ans = res[1];
	for (int i = 2; i <= n; i++) {
		res[i] = maxx;
		maxx = max(maxx, res[i] + f[i]);
		ans = max(ans, res[i]);
	}
	write(ans >= 0 ? ans % p : -(abs(ans) % p));
	return 0;
}
2024/8/18 17:06
加载中...