比赛 2025.4.12 评测结果 AAATTTTTTTT
题目名称 It s Mooin Time III 最终得分 27
用户昵称 LikableP 运行时间 15.997 s
代码语言 C++ 内存使用 1.47 MiB
提交时间 2025-04-12 08:43:38
显示代码纯文本
#include <cstdio>
typedef long long ll;

template <typename T>
T max(T x, T y) {
	return x > y ? x : y;
}

const int MAXN = 1e5 + 10;

int N, Q;
char str[MAXN];
ll maxx = -1;

int main() {
	freopen("Time.in", "r", stdin);
	freopen("Time.out", "w", stdout);
	scanf("%d %d", &N, &Q);
	scanf("%s", str + 1);
	while (Q--) {
		maxx = -1;
		int l, r;
		scanf("%d %d", &l, &r);
		for (int i = l; i <= r; ++i) {
			for (int j = i + 1; j <= r; ++j) {
				for (int k = j + 1; k <= r; ++k) {
					if (str[j] == str[k] && str[i] != str[j]) {
						maxx = max(maxx, (j - i) * 1ll * (k - j));
					}
				}
			}
		}
		printf("%lld\n", maxx);
	}
	return 0;
}