Problem p02681 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define N 100005
#define ll long long
#define ull unsigned long long
#define loop1(i, j, k, step) for (int i = j; i < k; i += step)
#define loop(i, j, k) for (int i = j; i < k; i++)
#define rloop1(i, j, k, step) for (int i = j; i >= k; i -= step)
#define rloop(i, j, k) for (int i = j; i >= k; i--)
#define rep(i, k) for (int i = (0); i < (k); i++)
#define rrep(i, k) for (int i = k - 1; i >= 0; i--)

#define forall(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define mp make_pair
#define pb push_back
#define pop pop_back
#define F first
#define S second
#define sz(x) (int)(x).size()
#define endl "\\n"
#define Max (int)INT_MAX
#define Min (int)INT_MIN
#define MEM(a, b) memset(a, (b), sizeof(a))
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL)
#define lin puts("");
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;
char ch[101][101];
char c;
int arr[105];
void solve() {
  string s, t;
  cin >> s;
  cin >> t;
  rep(i, s.size()) {
    if (s[i] != t[i]) {
      cout << "No" << endl;
      return;
    }
  }
  cout << "Yes" << endl;
}
int main() {
  auto start = clock();
  fast_io;
  // freopen("test.txt", "r", stdin);
  int t = 1;
  while (t--) {
    solve();
  }
  auto stop = clock();
  cerr << "time taken:" << double(stop - start) / double(CLOCKS_PER_SEC) << " s"
       << endl;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define N 100005
#define ll long long
#define ull unsigned long long
#define loop1(i, j, k, step) for (int i = j; i < k; i += step)
#define loop(i, j, k) for (int i = j; i < k; i++)
#define rloop1(i, j, k, step) for (int i = j; i >= k; i -= step)
#define rloop(i, j, k) for (int i = j; i >= k; i--)
#define rep(i, k) for (int i = (0); i < (k); i++)
#define rrep(i, k) for (int i = k - 1; i >= 0; i--)

#define forall(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define mp make_pair
#define pb push_back
#define pop pop_back
#define F first
#define S second
#define sz(x) (int)(x).size()
#define endl "\\n"
#define Max (int)INT_MAX
#define Min (int)INT_MIN
#define MEM(a, b) memset(a, (b), sizeof(a))
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL)
#define lin puts("");
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;
char ch[101][101];
char c;
int arr[105];
void solve() {
  int n, d, c = 0;
  cin >> n >> d;
  string s;
  cin >> s;
  rep(i, n) {

    if (s[i] == '1')
      arr[c++] = i;
  }
  int cnt = 0;
  int f = 0, r = 0, x = 0;
  for (int i = 0; i < c;) {
    int j = i + 1;
    while (j < c) {
      x = arr[j] - arr[i];
      if (x < d)
        j++;
      else if (x == d)
        break;
      else if (x > d) {
        j--;
        break;
      }
    }
    cnt++;
    if (x <= d && j == c - 1) {
      cout << cnt << endl;
      return;
    } else if (x > d && j == i) {
      cout << -1 << endl;
      return;
    }
    i = j;
  }
}
int main() {
  auto start = clock();
  fast_io;
  freopen("test.txt", "r", stdin);
  int t = 1;
  while (t--) {
    solve();
  }
  auto stop = clock();
  cerr << "time taken:" << double(stop - start) / double(CLOCKS_PER_SEC) << " s"
       << endl;
  return 0;
}