mle 求问怎么回事,谢谢
查看原帖
mle 求问怎么回事,谢谢
1286053
Cute_QiQi楼主2025/7/2 21:14
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair <int, int>
#define l first
#define r second
int n, p, a[100005], pre[100005];
queue <pii > q;
void BFS () {
	q.push({1, n});
	while (!q.empty()) {
		pii t = q.front();
		q.pop();
		if ((pre[t.r] - pre[t.l - 1]) % p == 0) {
			printf("%lld\n", t.r- t.l + 1);
			for (int i = t.l; i <= t.r; ++ i) {
				printf("%lld ", a[i]);
			}
			exit(0);
		}
		q.push({t.l + 1, t.r});
		q.push({t.l, t.r - 1});
	}
}
signed main () {
	scanf("%lld%lld", &n, &p);
	for (int i = 1; i <= n; ++ i) {
		scanf("%lld", &a[i]);
		pre[i] = pre[i - 1] + a[i];
	}
	BFS();
	printf("-1");
	return 0;
}
2025/7/2 21:14
加载中...