Problem p02571 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

// #include <bits/stdc++.h>
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;
typedef vector<cd> vcd;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef vector<vl> vvl;

#define FOR(i, a, b) for (int i = a; i < b; i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = b; i > a; i--)
#define F0Rd(i, a) for (int i = a; i > -1; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define pob pop_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define que queue
#define pa pair
#define ex(m, i) m.find(i) != m.end()
#define nex(m, i) m.find(i) == m.end()

#define uniq(x) x.resize(unique(all(x)) - x.begin())

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; // check the limits, dummy
const double epsilon = 1e-12;
const int ds[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);

  string s1, t1;
  cin >> s1 >> t1;

  int cmax = 0;
  int ci = 0;
  do {
    int t = 0;
    for (int i = ci; i < ci + sz(t1); i++) {
      if (s1[i] == t1[i - ci])
        t++;
    }
    cmax = max(cmax, t);

    if (ci + sz(t1) == sz(s1) - 1)
      break;
    ci++;
  } while (1);

  printf("%d\n", sz(t1) - cmax);

  return 0;
}

// read the question correctly (ll vs int)
// template by bqi343

Fixed submission:
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

// #include <bits/stdc++.h>
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;
typedef vector<cd> vcd;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef vector<vl> vvl;

#define FOR(i, a, b) for (int i = a; i < b; i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = b; i > a; i--)
#define F0Rd(i, a) for (int i = a; i > -1; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define pob pop_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define que queue
#define pa pair
#define ex(m, i) m.find(i) != m.end()
#define nex(m, i) m.find(i) == m.end()

#define uniq(x) x.resize(unique(all(x)) - x.begin())

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; // check the limits, dummy
const double epsilon = 1e-12;
const int ds[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);

  string s1, t1;
  cin >> s1 >> t1;

  int cmax = 0;
  int ci = 0;
  do {
    int t = 0;
    for (int i = ci; i < ci + sz(t1); i++) {
      if (s1[i] == t1[i - ci])
        t++;
    }
    cmax = max(cmax, t);
    // printf("%d\n",t);
    if (ci + sz(t1) >= sz(s1))
      break;
    ci++;
  } while (1);

  printf("%d\n", sz(t1) - cmax);

  return 0;
}

// read the question correctly (ll vs int)
// template by bqi343