Source Code
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int MAXN = 2e5 + 1;
int n, d, a[MAXN];

void solve() {
  cin >> n >> d;
  bool ans = false;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
    if(a[i] == d)
      ans = true;
  }
  int cnt = 0;
  if(d == 0) {
    for(int i = 1; i < n; i++) {
      if(a[i - 1] == a[i] && a[i - 1] == 0)
        while(i < n && a[i] == 0)
          cnt++, i++;
    }
  }
  cout << max(cnt, (ans) ? 1 : 0);
}
 
int main(){ 
  freopen("in.txt", "r", stdin);
  ios::sync_with_stdio(0);
  cin.tie(0);
  int TC = 1;   
  // cin >> TC;
  while(TC--) {
    solve();
  }
  return 0;
}
Copy
Legendary Ammar_Lahloh
GNU G++17
2 ms
772 KB
Wrong Answer