Source Code
#include <iostream>
#include <set>
#include <map>
#include <vector>
using namespace std;

int main() {
	int n, d, a[1000000];
	cin >> n >> d;
	vector<pair<int, int>> v;
	for(int i = 0; i < n; ++i){
		cin >> a[i];
	}
	int size = 1;
	for(int i = 1; i < n; ++i){
		if(a[i] != a[i - 1]){
			v.push_back({a[i - 1], size});
			size = 1;
		}
		else{
			++size;
		}
	}
	v.push_back({a[n - 1], size});
	int ans = 0;
	for(int i = 0; i < v.size(); ++i){
		if(v[i].first == 0 && 0 == d){
			ans = max(ans, v[i].second);
		}
		else if(v[i].second % 2 && v[i].first == d){
			ans = max(ans, v[i].second);
		}
	}
	cout << ans << endl;
	return 0;
}
Copy
Legendary Bahou
GNU G++17
3 ms
840 KB
Wrong Answer