#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;
// 判断移除一天后,剩余的数是否每种数字出现次数相同
bool checkSameCount(const vector<int>& nums, int left, int right, int removeIndex) {
unordered_map<int, int> countMap;
for (int i = left; i <= right; i) {
if (i == removeIndex) continue;
int num = nums[i];
countMap[num];
}
int firstCount = -1;
for (const auto& p : countMap) {
if (firstCount == -1) {
firstCount = p.second;
continue;
}
if (p.second!= firstCount) return false;
}
return true;
}
int main() {
int n;
cin >> n;
vector<int> nums(n);
for (int i = 0; i < n; ++i) {
cin >> nums[i];
}
int maxStreak = 0;
for (int left = 0; left < n; ++left) {
for (int right = left; right < n; ++right) {
int streak = right - left + 1;
for (int removeIndex = left; removeIndex <= right; ++removeIndex) {
if (checkSameCount(nums, left, right, removeIndex)) {
maxStreak = max(maxStreak, streak);
}
}
}
}
cout << maxStreak << endl;
return 0;
}
我用了第三之力豆包(doge)但是CF平台出错了,答案对了