Problem p02571 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <cmath>
#define ll long long
#define PI 3.14159265358979323846
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define pb emplace_back
#define watch5(a, b, c, d, e)                                                  \
  cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define watch4(a, b, c, d)                                                     \
  cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << endl;
#define watch3(a, b, c)                                                        \
  cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << endl;
#define watch2(a, b)                                                           \
  cerr << #a << ": " << a << " | " << #b << ": " << b << endl;
#define watch(a) cerr << #a << ": " << a << endl;
#define F first
#define S second
#define mod 1073741824
using namespace std;

int min(int a, int b) { return a < b ? a : b; }

int32_t main() {
  IOS;
  string s, t;
  cin >> s >> t;
  int ans = t.size();
  int n = s.size();
  int m = t.size();
  for (int i = 0; i < n - m + 1; i++) {
    int cnt = 0;
    for (int j = 0; j < m; j++) {
      watch2(i + j, j) if (s[i + j] != t[j]) {
        // watch2(s[i+j],t[j])
        cnt++;
      }
    }
    ans = min(ans, cnt);
  }
  cout << ans;
}

Fixed submission:
#include <bits/stdc++.h>
#include <cmath>
#define ll long long
#define PI 3.14159265358979323846
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define pb emplace_back
#define watch5(a, b, c, d, e)                                                  \
  cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define watch4(a, b, c, d)                                                     \
  cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << endl;
#define watch3(a, b, c)                                                        \
  cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << endl;
#define watch2(a, b)                                                           \
  cerr << #a << ": " << a << " | " << #b << ": " << b << endl;
#define watch(a) cerr << #a << ": " << a << endl;
#define F first
#define S second
#define mod 1073741824
using namespace std;

int min(int a, int b) { return a < b ? a : b; }

int32_t main() {
  IOS;
  string s, t;
  cin >> s >> t;
  int ans = t.size();
  int n = s.size();
  int m = t.size();
  for (int i = 0; i < n - m + 1; i++) {
    int cnt = 0;
    for (int j = 0; j < m; j++) {
      // watch2(i+j,j)
      if (s[i + j] != t[j]) {
        // watch2(s[i+j],t[j])
        cnt++;
      }
    }
    ans = min(ans, cnt);
  }
  cout << ans;
}